PoolEntry 参数讲解
- public abstract class PoolEntry<T, C> {
- private final String id;
- private final T route; //路由
- private final C conn; //http连接
- private final long created; //创建时间
- private final long validityDeadline;
- private long updated;
- private long expiry;
- private volatile Object state;
- }
构造方法:
- public PoolEntry(final String id, final T route, final C conn,
- final long timeToLive, final TimeUnit tunit) {
- super();
- Args.notNull(route, "Route");
- Args.notNull(conn, "Connection");
- Args.notNull(tunit, "Time unit");
- this.id = id;
- this.route = route;
- this.conn = conn;
- this.created = System.currentTimeMillis();
- this.updated = this.created;
- if (timeToLive > 0) {
- final long deadline = this.created + tunit.toMillis(timeToLive);
- // If the above overflows then default to Long.MAX_VALUE
- this.validityDeadline = deadline > 0 ? deadline : Long.MAX_VALUE;
- } else {
- this.validityDeadline = Long.MAX_VALUE;
- }
- this.expiry = this.validityDeadline;
- }
更新过期时间:
- public synchronized void updateExpiry(final long time, final TimeUnit tunit) {
- Args.notNull(tunit, "Time unit");
- this.updated = System.currentTimeMillis();
- final long newExpiry;
- if (time > 0) {
- newExpiry = this.updated + tunit.toMillis(time);
- } else {
- newExpiry = Long.MAX_VALUE;
- }
- this.expiry = Math.min(newExpiry, this.validityDeadline);
- }
1、http连接池管理一个连接对象,其实管理的是一个PoolEntry实例;
2、什么时候更新PoolEntry实例信息,比如过期时间,状态等?
在释放连接的时候会更新实例信息;
具体在:PoolingHttpClientConnectionManager.releaseConnection(final HttpClientConnection managedConn, final Object state, final long keepalive, final TimeUnit tunit) 方法中调用;但是这个方法是我们在释放response是调用的。
- public void releaseConnection(
- final HttpClientConnection managedConn,
- final Object state,
- final long keepalive, final TimeUnit tunit) {
- Args.notNull(managedConn, "Managed connection");
- synchronized (managedConn) {
- final CPoolEntry entry = CPoolProxy.detach(managedConn);
- if (entry == null) {
- return;
- }
- final ManagedHttpClientConnection conn = entry.getConnection();
- try {
- if (conn.isOpen()) {
- final TimeUnit effectiveUnit = tunit != null ? tunit : TimeUnit.MILLISECONDS;
- entry.setState(state);
- entry.updateExpiry(keepalive, effectiveUnit); //keepalive 参数表示长连接的过期时间,在客户端通过keepAliveStrategy参数设置
- if (this.log.isDebugEnabled()) {
- final String s;
- if (keepalive > 0) {
- s = "for " + (double) effectiveUnit.toMillis(keepalive) / 1000 + " seconds";
- } else {
- s = "indefinitely";
- }
- this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
- }
- conn.setSocketTimeout(0);
- }
- } finally {
- this.pool.release(entry, conn.isOpen() && entry.isRouteComplete());
- if (this.log.isDebugEnabled()) {
- this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
- }
- }
- }
- }
3、PoolingHttpClientConnectionManager 连接池参数 validateAfterInactivity说明:
当从连接池中拿到一个poolEntry时,如果validateAfterInactivity参数大于0 且 这个PoolEntry实例的updated加validateAfterInactivity小于等于当前时间,会检查这个连接(httpEntry实例中的con)的连接状态 state 值;
- org.apache.http.impl.BHttpConnectionBase
- public boolean isStale() {
- if (!isOpen()) {
- return true;
- }
- try {
- final int bytesRead = fillInputBuffer(1);
- return bytesRead < 0;
- } catch (final SocketTimeoutException ex) {
- return false;
- } catch (final IOException ex) {
- return true;
- }
- }
4、PoolingHttpClientConnectionManager 的关闭空闲超时连接方法:
指PoolEntry实例的更新时间加 空闲时间(设置)大于等于 当前时间,表示这个连接超过空闲时间
- public void closeIdleConnections(final long idleTimeout, final TimeUnit tunit) {
- if (this.log.isDebugEnabled()) {
- this.log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
- }
- this.pool.closeIdle(idleTimeout, tunit);
- }
5、PoolingHttpClientConnectionManager 的关闭过期连接方法:
指当前时间大于PoolEntry实例的expiry值
- public void closeExpiredConnections() {
- this.log.debug("Closing expired connections");
- this.pool.closeExpired();
- }
6、closeIdleConnections() 和 closeExpiredConnections() 对外提供,需要用户自己去调用,我们一般维护一个独立的线程去调用,清除空闲的连接和过期连接。
PoolEntry 参数讲解的更多相关文章
- android ui界面设计参数讲解
百度文库: http://wenku.baidu.com/link?url=s66Hw6byBEzmjL77doYL1YQN4Y_39F7MovaHKs5mVGrzTDOQCAmiM-1N_6Cdm- ...
- libsvm 训练后的模型参数讲解(转)
主要就是讲解利用libsvm-mat工具箱建立分类(回归模型)后,得到的模型model里面参数的意义都是神马?以及如果通过model得到相应模型的表达式,这里主要以分类问题为例子.测试数据使用的是li ...
- [转]libsvm 训练后的模型参数讲解
http://blog.sina.com.cn/s/blog_6646924501018fqc.html 主要就是讲解利用libsvm-mat工具箱建立分类(回归模型)后,得到的模型model里面参数 ...
- Log4J入门教程(二) 参数讲解
继续接着Log4J入门教程(一)中的例子进行讲解,其中log4j.properties中的内容为 Log4j的三个重要组件—— Loggers, Appenders, Layouts ,这三个组 ...
- Java Socket重要参数讲解
(转自http://www.cnblogs.com/ggjucheng/archive/2012/01/06/2314679.html) ( http://docs.oracle.com/javase ...
- job_queue_processes参数讲解
http://blog.sina.com.cn/s/blog_62defbef0101opv0.html http://blog.163.com/donfang_jianping/blog/stati ...
- Java可变参数讲解
如果实现的多个方法,这些方法里面逻辑基本相同,唯一不同的是传递的参数的个数,可以使用可变参数可变参数的定义方法 数据类型...数组的名称,这个数组存储传递过来的参数,类似JavaScript注意点: ...
- arm-linux-gcc 常用参数讲解 gcc编译器使用方法
我们需要编译出运行在ARM平台上的代码,所使用的交叉编译器为 arm-linux-gcc.下面将arm-linux-gcc编译工具的一些常用命令参数介绍给大家.在此之前首先介绍下编译器的工作过程,在使 ...
- droppable的详细参数讲解
jQuery-Draggable参数介绍 默认设置值: $.extend($.ui.draggable, { version: “1.7.1″, eventPrefix: “drag”, de ...
随机推荐
- Django入门三之urls.py重构及参数传递
1. 内部重构 2. 外部重构 website/blog/urls.py website/website/urls.py 3. 两种参数处理方式 -1. blog/index/?id=1234& ...
- jq slideToggle()坑
jQuery slideToggle() 方法 jQuery slideToggle() 方法可以在 slideDown() 与 slideUp() 方法之间进行切换. 如果元素向下滑动,则 slid ...
- SQL之left join,inner join,right join
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...
- Spring Boot常用注解总结
Spring Boot常用注解总结 @RestController和@RequestMapping注解 @RestController注解,它继承自@Controller注解.4.0之前的版本,Spr ...
- vue技术分享-你可能不知道的7个秘密
前言 本文是vue源码贡献值Chris Fritz在公共场合的一场分享,觉得分享里面有不少东西值得借鉴,虽然有些内容我在工作中也是这么做的,还是把大神的ppt在这里翻译一下,希望给朋友带来一些帮助. ...
- Zookeeper学习
http://www.cnblogs.com/caosiyang/archive/2012/11/09/2763190.html http://www.cnblogs.com/haippy/tag ...
- java线程间通信之通过管道进行通信
管道流PipeStream是一种特殊的流,用于在不同线程间直接传送数据,而不需要借助临时文件之类的东西. jdk中提供了四个类来使线程间可以通信: 1)PipedInputStream和PipedOu ...
- 功能强大的swagger-editor的介绍与使用
一.Swagger Editor简介 Swagger Editor是一个开源的编辑器,并且它也是一个基于Angular的成功案例.在Swagger Editor中,我们可以基于YAML等语法定义我们的 ...
- Android TagFlowLayout完全解析 一款针对Tag的布局
转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/48393217: 本文出自:[张鸿洋的博客] 一.概述 本文之前,先提一下关于上 ...
- Android监测手指上下左右滑动屏幕
在开发android程序时,有时会需要监测手指滑动屏幕,当手指朝上下左右不同方向滑动时做出不同的响应,那怎么去实现呢? 利用Android提供的手势监测器就可以很方便的实现,直接上代码(已测试通过) ...