线程用来清理 http连接池无效的链接 :

    1. package com.**.weixin.common.https;  
    2.   
    3. import java.util.concurrent.TimeUnit;  
    4.   
    5. import org.apache.http.conn.HttpClientConnectionManager;  
    6.   
    7. /** 
    8.  * <p>Description: 使用管理器,管理HTTP连接池 无效链接定期清理功能</p>  
    9.  *  
    10.  */  
    11. public class HttpClientConnectionMonitorThread extends Thread {  
    12.   
    13.     private final HttpClientConnectionManager connManager;  
    14.     private volatile boolean shutdown;  
    15.   
    16.     public HttpClientConnectionMonitorThread(HttpClientConnectionManager connManager) {  
    17.         super();  
    18.         this.setName("http-connection-monitor");  
    19.         this.setDaemon(true);  
    20.         this.connManager = connManager;  
    21.         this.start();  
    22.     }  
    23.   
    24.     @Override  
    25.     public void run() {  
    26.         try {  
    27.             while (!shutdown) {  
    28.                 synchronized (this) {  
    29.                     wait(5000); // 等待5秒  
    30.                     // 关闭过期的链接  
    31.                     connManager.closeExpiredConnections();  
    32.                     // 选择关闭 空闲30秒的链接  
    33.                     connManager.closeIdleConnections(30, TimeUnit.SECONDS);  
    34.                 }  
    35.             }  
    36.         } catch (InterruptedException ex) {  
    37.         }  
    38.     }  
    39.       
    40.     /** 
    41.      * 方法描述: 停止 管理器 清理无效链接  (该方法当前暂时关闭)  
    42.      * @author andy 2017年8月28日 下午1:45:18 
    43.      */  
    44.     @Deprecated  
    45.     public void shutDownMonitor() {  
    46.         synchronized (this) {  
    47.             shutdown = true;  
    48.             notifyAll();  
    49.         }  
    50.     }  
    51.   
    52. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值