Quick Server (1.4.6 版本)的对象池是交给org.quickserver.net.server.PoolManager管理的,框架中其唯一的实现类是org.quickserver.net.server.impl.BasicPoolManager。
先看下quick server的配置文件中关于 object-pool的配置项:
其中可配置4种对象池,如果不对4种池专门配置,则共享<object-pool>的max-active、max-idle、init-size参数值。4种池是相互独立的。看BasicPoolManager源码:
ClientPool,ClientHandlerPool,ClientDataPool,ByteBufferPool4种池对象都是org.apache.commons.pool.impl.GenericObjectPool的实例。GenericObjectPool是抽象类BaseObjectPool的子类,其池基于org.apache.commons.collections.CursorableLinkedList实现,是List的一个实现。
先看下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的一个实现。