List of usage examples for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool
public GenericObjectPool(PooledObjectFactory<T> factory, GenericObjectPoolConfig config)
GenericObjectPool
using a specific configuration. From source file:me.smoe.adar.pool.commonpool.CommonPool.java
public static void main(String[] args) throws NoSuchElementException, IllegalStateException, Exception { GenericObjectPool<Book> objectPool = new GenericObjectPool<Book>(new BookPoolFactory(), buildPoolConfig(5, 10, 2));// www . j ava 2 s. co m prestartCorePool(objectPool); List<Book> books = new LinkedList<Book>(); for (int i = 0; i < 10; i++) { books.add(objectPool.borrowObject()); } for (Book book : books) { objectPool.returnObject(book); } }
From source file:com.mycila.xmltool.XMLDocumentBuilderFactory.java
public static void setPoolConfig(GenericObjectPoolConfig config) { ignoreNamespaceDocumentBuilderPool = new GenericObjectPool<DocumentBuilder>( new BasePooledObjectFactory<DocumentBuilder>() { @Override//ww w . j a v a2s . c o m public DocumentBuilder create() throws Exception { return newDocumentBuilder(true); } @Override public PooledObject<DocumentBuilder> wrap(DocumentBuilder obj) { return new DefaultPooledObject<DocumentBuilder>(obj); } }, config); namespaceAwareDocumentBuilderPool = new GenericObjectPool<DocumentBuilder>( new BasePooledObjectFactory<DocumentBuilder>() { @Override public DocumentBuilder create() throws Exception { return newDocumentBuilder(false); } @Override public PooledObject<DocumentBuilder> wrap(DocumentBuilder obj) { return new DefaultPooledObject<DocumentBuilder>(obj); } }, config); }
From source file:com.navercorp.redis.cluster.Pool.java
public Pool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) { this.internalPool = new GenericObjectPool<T>(factory, poolConfig); }
From source file:com.mycompany.amfclient.ConnectionPool.java
private ConnectionPool() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(200);//from w w w. jav a 2 s.com this.connectionPool = new GenericObjectPool(ConnectionPooledFactory.inst(), config); }
From source file:com.dempe.lamp.client.ChannelPool.java
public ChannelPool(CommonClient rpcClient) { objectFactory = new ChannelPoolObjectFactory(rpcClient); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); pool = new GenericObjectPool<Connection>(objectFactory, config); }
From source file:com.baidu.jprotobuf.pbrpc.utils.Pool.java
/** * Instantiates a new pool./* ww w . ja v a 2 s .com*/ * * @param poolConfig the pool config * @param factory the factory */ public Pool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) { this.internalPool = new GenericObjectPool<T>(factory, poolConfig); }
From source file:com.github.chrishantha.microbenchmark.objectpool.CommonsPool2GenericObjectPoolBenchmark.java
@Override public void setupObjectPool() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(poolSize);//w w w . j a v a 2s . co m 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); }
From source file:com.sky.projects.pool.PoolBase.java
/** * ?// ww w. j a va 2 s.c o m * * @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); }
From source file:com.test.database.jedis.pool.Pool.java
public void initPool(GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) { if (this.internalPool != null) { try {//from w w w.j a va 2 s. co m closeInternalPool(); } catch (Exception e) { } } this.internalPool = new GenericObjectPool<T>(factory, poolConfig); }
From source file:com.xyxy.platform.modules.nosql.redis.pool.JedisPool.java
/** * Initialize the internal pool with connection info and pool config. *///w w w . j a v a 2 s .com protected void initInternalPool(HostAndPort address, ConnectionInfo connectionInfo, JedisPoolConfig config) { this.address = address; this.connectionInfo = connectionInfo; JedisFactory factory = new JedisFactory(address.getHost(), address.getPort(), connectionInfo.getTimeout(), connectionInfo.getPassword(), connectionInfo.getDatabase()); internalPool = new GenericObjectPool(factory, config); }