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的一个实现。
本文详细介绍了QuickServer 1.4.6版本中对象池的管理机制,包括组织架构、配置项及其实现方式。通过分析QuickServer配置文件中的object-pool部分,解释了四种不同类型的对象池(ByteBufferPool、ClientPool、ClientHandlerPool、ClientDataPool)如何基于org.apache.commons.pool.impl.GenericObjectPool进行实例化,并探讨了它们之间的相互独立性。

被折叠的 条评论
为什么被折叠?



