我们正在编写一个简单的独立 java 批处理。我们正在使用 DB2 数据库。我们正在尝试使用 UCP(版本:ucp-11.2.0.3.0)进行连接池。
我们已将最小池大小初始化为 5。但是当我们检索一个连接并打印可用和借用连接时,我们将可用为 0 和借用为 1。当检索多个连接时,它仍然打印相同,即使最小池大小为 5。即使超过了最大限制,我们也没有得到任何异常。你能帮我们解决这个问题吗?
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("XXXX");
pds.setURL("XXX");
pds.setUser("CCCC");
pds.setPassword("xxx");
pds.setInitialPoolSize(1);
pds.setMinPoolSize(5);
pds.setMaxPoolSize(10);
connection = pds.getConnection();
System.out.println("\nConnection borrowed from the pool");
int avlConnCount = pds.getAvailableConnectionsCount();
System.out.println("\nAvailable connections: " + avlConnCount);
int brwConnCount = pds.getBorrowedConnectionsCount();
System.out.println("\nBorrowed connections: " + brwConnCount);
Output: ------- Connection borrowed from the pool Available connections: 0 Borrowed connections: 1 Connection borrowed from the pool Available connections: 0 Borrowed connections: 1