本文整理匯總了Java中org.apache.commons.pool2.BasePooledObjectFactory類的典型用法代碼示例。如果您正苦於以下問題:Java BasePooledObjectFactory類的具體用法?Java BasePooledObjectFactory怎麽用?Java BasePooledObjectFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BasePooledObjectFactory類屬於org.apache.commons.pool2包,在下文中一共展示了BasePooledObjectFactory類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupObjectPool
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
@Override
public void setupObjectPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(poolSize);
objectPool = new GenericObjectPool<>(new BasePooledObjectFactory<TestObject>() {
@Override
public TestObject create() throws Exception {
return new TestObject(true);
}
@Override
public PooledObject<TestObject> wrap(TestObject testObject) {
return new DefaultPooledObject<>(testObject);
}
}, config);
}
示例2: setupObjectPool
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
@Override
public void setupObjectPool() {
objectPool = new SoftReferenceObjectPool<>(new BasePooledObjectFactory<TestObject>() {
@Override
public TestObject create() throws Exception {
return new TestObject(true);
}
@Override
public PooledObject<TestObject> wrap(TestObject testObject) {
return new DefaultPooledObject<>(testObject);
}
});
}
開發者ID:chrishantha,項目名稱:microbenchmarks,代碼行數:15,代碼來源:CommonsPool2SoftReferenceObjectPoolBenchmark.java
示例3: messagePoolFactory
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
private BasePooledObjectFactory<PollableChannel> messagePoolFactory() {
return new BasePooledObjectFactory<PollableChannel>() {
@Override
public PollableChannel create()
throws Exception {
return new QueueChannel(10);
}
@Override
public PooledObject<PollableChannel> wrap(PollableChannel obj) {
return new DefaultPooledObject<PollableChannel>(obj);
}
};
}
示例4: OperativeFactoryImpl
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
/**
* Creates a new OperativeFactoryImpl object.
*
* @param activeOperativePoolFactory .
*/
public OperativeFactoryImpl(BasePooledObjectFactory<Operative> activeOperativePoolFactory,
BasePooledObjectFactory<Operative> passiveOperativePoolFactory) {
if (activeOperativePoolFactory != null) {
activeOperativePool = new GenericObjectPool<Operative>(activeOperativePoolFactory);
}
if (passiveOperativePoolFactory != null) {
passiveOperativePool = new GenericObjectPool<Operative>(passiveOperativePoolFactory);
}
}
示例5: createBasePooledObjectfactory
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
private BasePooledObjectFactory<String> createBasePooledObjectfactory() {
return new BasePooledObjectFactory<String>() {
@Override
public String create() {
// fake
return null;
}
@Override
public PooledObject<String> wrap(final String obj) {
// fake
return null;
}
};
}
示例6: PooledSphinxDataSource
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
public PooledSphinxDataSource(BasePooledObjectFactory<SphinxClient> factory) {
this(new GenericObjectPool<SphinxClient>(factory));
}
示例7: JdbcConnectionPoolDemo
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
public JdbcConnectionPoolDemo() {
initPool(new PoolConfig(), new BasePooledObjectFactory<Connection>() {
@Override
public Connection create() throws Exception {
return null;
}
@Override
public PooledObject<Connection> wrap(Connection obj) {
return null;
}
});
}
示例8: testEvictionSoftMinIdle
import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
@Test(timeout=60000)
public void testEvictionSoftMinIdle() throws Exception {
class TimeTest extends BasePooledObjectFactory<TimeTest> {
private final long createTime;
public TimeTest() {
createTime = System.currentTimeMillis();
}
@Override
public TimeTest create() throws Exception {
return new TimeTest();
}
@Override
public PooledObject<TimeTest> wrap(final TimeTest value) {
return new DefaultPooledObject<>(value);
}
public long getCreateTime() {
return createTime;
}
}
try (final GenericObjectPool<TimeTest> timePool = new GenericObjectPool<>(new TimeTest())) {
timePool.setMaxIdle(5);
timePool.setMaxTotal(5);
timePool.setNumTestsPerEvictionRun(5);
timePool.setMinEvictableIdleTimeMillis(3000L);
timePool.setSoftMinEvictableIdleTimeMillis(1000L);
timePool.setMinIdle(2);
final TimeTest[] active = new TimeTest[5];
final Long[] creationTime = new Long[5];
for (int i = 0; i < 5; i++) {
active[i] = timePool.borrowObject();
creationTime[i] = Long.valueOf((active[i]).getCreateTime());
}
for (int i = 0; i < 5; i++) {
timePool.returnObject(active[i]);
}
// Soft evict all but minIdle(2)
Thread.sleep(1500L);
timePool.evict();
assertEquals("Idle count different than expected.", 2, timePool.getNumIdle());
// Hard evict the rest.
Thread.sleep(2000L);
timePool.evict();
assertEquals("Idle count different than expected.", 0, timePool.getNumIdle());
}
}