本文整理汇总了Java中org.apache.commons.pool2.PooledObjectFactory类的典型用法代码示例。如果您正苦于以下问题:Java PooledObjectFactory类的具体用法?Java PooledObjectFactory怎么用?Java PooledObjectFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PooledObjectFactory类属于org.apache.commons.pool2包,在下文中一共展示了PooledObjectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GenericObjectPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
/**
* 使用特定的配置来创建一个新的"通用对象池"实例。
* <p>
* Create a new <code>GenericObjectPool</code> using a specific
* configuration.
*
* @param factory The object factory to be used to create object instances
* used by this pool (用于创建"池对象"实例的对象工厂)
* @param config The 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. (随后对配置对象的更改将不会反映到对象池中)
*/
public GenericObjectPool(PooledObjectFactory<T> factory,
GenericObjectPoolConfig config) {
super(config, ONAME_BASE, config.getJmxNamePrefix());
if (factory == null) {
jmxUnregister(); // tidy up
throw new IllegalArgumentException("factory may not be null");
}
this.factory = factory;
this.setConfig(config);
// 启动"驱逐者线程"
this.startEvictor(this.getTimeBetweenEvictionRunsMillis());
}
示例2: GenericObjectPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
/**
* Create a new <code>GenericObjectPool</code> using a specific
* configuration.
*
* @param factory The object factory to be used to create object instances
* used by this pool
* @param config The 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.
*/
public GenericObjectPool(final PooledObjectFactory<T> factory,
final GenericObjectPoolConfig config) {
super(config, ONAME_BASE, config.getJmxNamePrefix());
if (factory == null) {
jmxUnregister(); // tidy up
throw new IllegalArgumentException("factory may not be null");
}
this.factory = factory;
idleObjects = new LinkedBlockingDeque<>(config.getFairness());
setConfig(config);
startEvictor(getTimeBetweenEvictionRunsMillis());
}
示例3: setUp
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
@Before
public void setUp() {
log = new StringWriter();
final PrintWriter pw = new PrintWriter(log);
final AbandonedConfig abandonedConfig = new AbandonedConfig();
abandonedConfig.setLogAbandoned(true);
abandonedConfig.setRemoveAbandonedOnBorrow(true);
abandonedConfig.setUseUsageTracking(true);
abandonedConfig.setRemoveAbandonedTimeout(ABANDONED_TIMEOUT_SECS);
abandonedConfig.setLogWriter(pw);
final GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(3);
final PooledObjectFactory<TestObject> factory = new TestObjectFactory();
final ObjectPool<TestObject> innerPool =
new GenericObjectPool<>(factory, config, abandonedConfig);
pool = new ProxiedObjectPool<>(innerPool, getproxySource());
}
示例4: initPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) {
if (this.internalPool != null) {
try {
closeInternalPool();
} catch (Exception e) {
}
}
this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
}
示例5: initPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) {
if (this.internalPool != null) {
try {
closeInternalPool();
} catch (Exception e) {
}
}
this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
}
示例6: initPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<KuduClient> factory)
{
if (this.internalPool != null) {
try {
closeInternalPool();
}
catch (Exception e) {
}
}
this.internalPool = new GenericObjectPool<KuduClient>(factory, poolConfig);
}
示例7: Pool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public Pool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) {
initPool(poolConfig, factory);
}
示例8: initPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
/**
* <p>Title: initPool</p>
* <p>Description: 初始化对象池</p>
*
* @param poolConfig 池配置
* @param factory 池对象工厂
*/
protected void initPool(final GenericObjectPoolConfig poolConfig,
PooledObjectFactory<T> factory) {
if (this.internalPool != null)
this.destroy();
this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
}
示例9: initPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<Client> factory) {
if (this.internalPool != null) {
try {
closeInternalPool();
} catch (Exception e) {
//ignore
}
}
this.internalPool = new GenericObjectPool<Client>(factory, poolConfig);
}
示例10: initPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
/**
* 初始化"连接池"。
*
* @param poolConfig
* 连接池配置信息
* @param factory
* 连接池对象的工厂
*/
public void initPool(GenericObjectPoolConfig poolConfig,
PooledObjectFactory<R> factory) {
// 若原有的连接池资源未被释放,则先关闭
if (this.internalPool != null) {
try {
this.closeInternalPool();
} catch (Exception e) {
}
}
this.internalPool = new GenericObjectPool<R>(factory, poolConfig);
}
示例11: createObjectPool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
private static <T> ObjectPool<T> createObjectPool(final PooledObjectFactory<T> factory) {
final GenericObjectPoolConfig objectPoolConfig = new GenericObjectPoolConfig();
objectPoolConfig.setMinEvictableIdleTimeMillis(TimeUnit.HOURS.toMillis(1)); // arbitrary, but positive so objects do get evicted
objectPoolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES.toMillis(10)); // arbitrary, but positive so objects do get evicted
objectPoolConfig.setJmxEnabled(false);
objectPoolConfig.setBlockWhenExhausted(false);
objectPoolConfig.setMaxTotal(-1); // uncapped number of objects in the pool
final AbandonedConfig abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnBorrow(true);
abandonedConfig.setRemoveAbandonedTimeout((int) TimeUnit.MINUTES.toSeconds(30));
return new GenericObjectPool<T>(factory, objectPoolConfig, abandonedConfig);
}
示例12: Pool
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public Pool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) {
initPool(poolConfig, factory);
}
示例13: KryoPoolCommonsImpl
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public KryoPoolCommonsImpl(GenericObjectPoolConfig genericObjectPoolConfig, PooledObjectFactory<Kryo> pooledObjectFactory, AbandonedConfig abandonedConfig, FKCExceptionHandler fkcExceptionHandler) {
this.kryoPool = new GenericObjectPool<Kryo>(pooledObjectFactory, genericObjectPoolConfig, abandonedConfig);
this.fkcExceptionHandler = fkcExceptionHandler;
}
示例14: CommonsBuilder
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public CommonsBuilder(PooledObjectFactory<Kryo> kryoPooledObjectFactory) {
if (kryoPooledObjectFactory == null) {
throw new IllegalArgumentException("pooledObjectFactory must not be null");
}
this.pooledObjectFactory = kryoPooledObjectFactory;
}
示例15: setPooledObjectFactory
import org.apache.commons.pool2.PooledObjectFactory; //导入依赖的package包/类
public void setPooledObjectFactory(PooledObjectFactory<Kryo> pooledObjectFactory) {
this.pooledObjectFactory = pooledObjectFactory;
}