【发布时间】:2019-12-29 11:27:00
【问题描述】:
我们正在编写一个简单的独立 java 批处理。我们正在使用 DB2 数据库。我们正在尝试使用 UCP(版本:ucp-11.2.0.3.0)进行连接池。
我们已将最小池大小初始化为 5。但是当我们检索一个连接并打印 Available 和 Borrowed 连接时,我们得到 Available 为 0 和 Borrowed 为 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
【问题讨论】:
-
您为什么认为 Oracle UCP 应该与 Db2 一起使用? IBM 似乎只支持 Oracle 数据库的 UCP(通过 WAS)。