本文整理匯總了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;
}