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的一个实现。

你可能感兴趣的:(apache,thread,.net,项目管理,配置管理)