Я использую реализацию Apache Commons Pool 2 для создания механизма пула объектов для моего приложения.
Ниже приведена конфигурация для создания пула
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
poolableConnectionFactory.setPoolStatements(poolPreparedStatements);
poolableConnectionFactory.setValidationQuery(testConnectionSql);
poolableConnectionFactory.setDefaultReadOnly(Boolean.TRUE);
poolableConnectionFactory.setDefaultAutoCommit(Boolean.TRUE);
poolableConnectionFactory.setDefaultTransactionIsolation(-1);
poolableConnectionFactory.setDefaultCatalog(null);
GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
connectionPool.setMaxTotal(4);
connectionPool.setMaxIdle(2);
connectionPool.setTestOnBorrow(false);
connectionPool.setTestOnReturn(false);
connectionPool.setTestWhileIdle(false);
poolableConnectionFactory.setPool(connectionPool);
dataSource_ = new PoolingDataSource(connectionPool);
maxtotal value is 4. But in DB, 13 connections are opened.