我的应用程序使用Oracle UCP侦听一些表。在生产环境中,应用程序工作正常,但在测试环境中,应用程序用尽了池中的连接。我也在每个查询中关闭并返回使用的连接。请参考连接关闭方法。
public static synchronized void closeConnection(Connection con) throws Exception {
String print;
try {
if (con != null && !con.isClosed()) {
con.close();
con =null;
Config.DB_POOL_COUNT_AVAILABLE = pds.getAvailableConnectionsCount();
Config.DB_POOL_COUNT_BUSSY = pds.getBorrowedConnectionsCount();
Config.DB_POOL_COUNT_OPENED = Config.DB_POOL_COUNT_AVAILABLE + Config.DB_POOL_COUNT_BUSSY;
} else {
Config.DB_POOL_COUNT_AVAILABLE = pds.getAvailableConnectionsCount();
Config.DB_POOL_COUNT_BUSSY = pds.getBorrowedConnectionsCount();
Config.DB_POOL_COUNT_OPENED = Config.DB_POOL_COUNT_AVAILABLE + Config.DB_POOL_COUNT_BUSSY;
}
} catch (Exception e) {
Logger.errorLog(e);
} finally {
Config.DB_POOL_COUNT_AVAILABLE = pds.getAvailableConnectionsCount();
Config.DB_POOL_COUNT_BUSSY = pds.getBorrowedConnectionsCount();
Config.DB_POOL_COUNT_OPENED = Config.DB_POOL_COUNT_AVAILABLE + Config.DB_POOL_COUNT_BUSSY;
if(con != null && !con.isClosed()){
con.close();
con=null;
}
}
}
答案 0 :(得分:0)
由于您的应用程序在生产环境中运行良好,因此您无需过多地担心连接池。在开发环境中,查询后关闭连接还不错。
有关Oracle UCP的良好实践,请访问https://docs.oracle.com/cd/E18283_01/java.112/e12265/optimize.htm或
https://docs.oracle.com/en/database/oracle/oracle-database/18/jjucp/optimizing-ucp-behavior.html