/** * Creates a new {@code GenericObjectPool} that tracks and destroys * objects that are checked out, but never returned to the pool. * * @param factory The object factory to be used to create object instances * used by this pool * @param config The base pool configuration to use for this pool instance. * The configuration is used by value. Subsequent changes to * the configuration object will not be reflected in the * pool. * @param abandonedConfig Configuration for abandoned object identification * and removal. The configuration is used by value. */ publicGenericObjectPool(final PooledObjectFactory factory, final GenericObjectPoolConfig config, final AbandonedConfig abandonedConfig){ }
/** * The default value for the {@code maxTotal} configuration attribute. * @see GenericObjectPool#getMaxTotal() */ publicstaticfinalint DEFAULT_MAX_TOTAL = 8;
/** * The default value for the {@code maxIdle} configuration attribute. * @see GenericObjectPool#getMaxIdle() */ publicstaticfinalint DEFAULT_MAX_IDLE = 8;
/** * The default value for the {@code minIdle} configuration attribute. * @see GenericObjectPool#getMinIdle() */ publicstaticfinalint DEFAULT_MIN_IDLE = 0;
通过调整这些参数值,就能创建符合业务要求的池子。下面就是能常驻4个进程的一套配置参数。
private GenericObjectPoolConfiggenericObjectPoolConfig(){ final GenericObjectPoolConfig config = new GenericObjectPoolConfig<>();