QuickServer的学习研究(九)

在一般的项目中经常使用各种资源池,如线程池,连接池,对象池等,在Apache项目中常用为Commons-dbcp的数据库连接池,主要为实现Commons-pool资源池的接口特定接口和类:import org.apache.commons.pool.BasePoolableObjectFactory; 在QuickServer中使用的资源池有:线程池和对象池等,如: public class ThreadObjectFactory extends BasePoolableObjectFactory:

 

Quick Server (1.4.6 版本)的对象池是交给org.quickserver.net.server.PoolManager管理的,框架中其唯一的实现类是org.quickserver.net.server.impl.BasicPoolManager。
   先看下quick server的配置文件中关于 object-pool的配置项:

<object-pool>
<max-active>..</max-active>
<max-idle>..</max-idle>
<init-size>..</init-size>
<thread-object-pool>
..  
</thread-object-pool>
<client-handler-object-pool>
..
</client-handler-object-pool>
<byte-buffer-object-pool>
..
</byte-buffer-object-pool>  
<client-data-object-pool>
..
</client-data-object-pool>
</object-pool>

其中可配置4种对象池,如果不对4种池专门配置,则共享<object-pool>的max-active、max-idle、init-size参数值。4种池是相互独立的。看BasicPoolManager源码:

public ObjectPool makeByteBufferPool(PoolableObjectFactory factory, PoolConfig opConfig)
/*    */   {
/* 36 */     GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
/* 37 */     bconfig.maxActive = opConfig.getMaxActive();
/* 38 */     bconfig.maxIdle = opConfig.getMaxIdle();
/* 39 */     bconfig.whenExhaustedAction = 1;
/* 40 */     return new GenericObjectPool(factory, bconfig);
/*    */   }
/*    */
/*    */   public ObjectPool makeClientPool(PoolableObjectFactory factory, PoolConfig opConfig)
/*    */   {
/* 45 */     GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
/* 46 */     bconfig.maxActive = opConfig.getMaxActive();
/* 47 */     bconfig.maxIdle = opConfig.getMaxIdle();
/* 48 */     bconfig.whenExhaustedAction = 0;
/* 49 */     return new GenericObjectPool(factory, bconfig);
/*    */   }
/*    */
/*    */   public ObjectPool makeClientHandlerPool(PoolableObjectFactory factory, PoolConfig opConfig)
/*    */   {
/* 54 */     GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
/* 55 */     bconfig.maxActive = opConfig.getMaxActive();
/* 56 */     bconfig.maxIdle = opConfig.getMaxIdle();
/*    */
/* 58 */     bconfig.whenExhaustedAction = 0;
/* 59 */     return new GenericObjectPool(factory, bconfig);
/*    */   }
/*    */
/*    */   public ObjectPool makeClientDataPool(PoolableObjectFactory factory, PoolConfig opConfig)
/*    */   {
/* 64 */     GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
/* 65 */     bconfig.maxActive = opConfig.getMaxActive();
/* 66 */     bconfig.maxIdle = opConfig.getMaxIdle();
/* 67 */     bconfig.whenExhaustedAction = 0;
/* 68 */     return new GenericObjectPool(factory, bconfig);
/*    */   }

ClientPool,ClientHandlerPool,ClientDataPool,ByteBufferPool4种池对象都是org.apache.commons.pool.impl.GenericObjectPool的实例。GenericObjectPool是抽象类BaseObjectPool的子类,其池基于org.apache.commons.collections.CursorableLinkedList实现,是List的一个实现。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值