List of usage examples for org.apache.commons.pool2.impl GenericObjectPool setMaxIdle
public void setMaxIdle(int maxIdle)
From source file:org.aludratest.cloud.impl.app.LogDatabase.java
private Connection getConnection() throws SQLException { if (dataSource == null) { EmbeddedDataSource ds = new EmbeddedDataSource(); ds.setDatabaseName("acm"); ConnectionFactory connectionFactory = new DataSourceConnectionFactory(ds); PoolableConnectionFactory objFactory = new PoolableConnectionFactory(connectionFactory, null); objFactory.setValidationQuery("VALUES 1"); objFactory.setDefaultAutoCommit(true); // max 10 minutes lifetime objFactory.setMaxConnLifetimeMillis(1000l * 60 * 10); // must be fast, because is local objFactory.setValidationQueryTimeout(5); GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(objFactory); pool.setMaxIdle(2); dataSource = new PoolingDataSource<PoolableConnection>(pool); }/*from w w w .ja va2 s . co m*/ return dataSource.getConnection(); }