
# 使用超时功能
clientcontrol提供了超时功能，当目标业务方法执行超过执行时间后，会终止代码的执行，具体使用方式如下：
1. [pom文件添加依赖](https://support.huaweicloud.com/devg-astropro/astropro_06_0079.html#astropro_06_0079__li1026515252452)。
2. 配置文件，参考下面配置样例。
   ```
   devspore:
     client-control:
       biz-pool:
         prioritized: false
         core-pool-size: 20
         maximum-pool-size: 32
         keep-alive-time-ms: 60000
         work-queue-size: 5000
         rejectedExecutionHandlerClassName: java.util.concurrent.ThreadPoolExecutor$AbortPolicy #此处配置的线程池的拒绝策略
       rules:
         timeLimitTest:  # 此处配置的是一个别名，用户可自定义，具体使用地方是在注解上
           match: ^.*$
           module: RetryFirst
           time-limit:
             enable: true
             timeout-duration: 3000  # 此处配置的是超时时间
             cancel-running-future: true
           retry:
             enable: false  # 重试功能默认开启，当只使用超时功能时，此处手动关闭
           fallback:
             enable: false  # 熔断功能默认开启，当只使用超时功能时，此处手动关闭
   ```
   
3. 在目标方法上添加@ClientControl注解，且rule属性指定用户在配置文件中自定义的rules名称（本示例使用timeLimitTest）。
   ```
   //  在想要使用超时功能的方法上添加 @ClientControl注解， 属性值rule 填写配置文件中自定义的名称
   @ClientControl(rule = "timeLimitTest")
   public String testTimelimit(long sleepTime) {
   try {
   Thread.sleep(sleepTime);
   } catch (InterruptedException e) {
   throw new RuntimeException(e);
   }
   return "测试超时";
   }
   ```
   
#### 注意事项
- 当使用超时功能时，方法会运行在异步线程中，如在方法中使用了线程变量，会产生无法读取变量的问题。
- 使用超时功能时必须配置线程池devspore:client-control:biz-pool，具体参数配置请参考[表1](https://support.huaweicloud.com/devg-astropro/astropro_06_0087.html#astropro_06_0087__table1270555113712)。
 
