需要解释 [java.util.NoSuchElementException:等待空闲对象超时]
Need explanation about [java.util.NoSuchElementException: Timeout waiting for idle object]
我通过调用波纹管方法 48 次 +/-
得到了上述异常
public ResultSet executePreparedStatement(String preparedStatementQuery, List<?> parameters) throws Exception {
CachedRowSetImpl rowSet = null;
PreparedStatement preparedStatement = null;
Connection connection = connectionPool.getConnection(); // The problem is with this line
try {
connection = connectionPool.getConnection();
preparedStatement = connection.prepareStatement(preparedStatementQuery);
for (int i=0;i<parameters.size();i++) {
preparedStatement.setObject(i+1, parameters.get(i));
}
if (SQLHelper.doesQueryReturnsResultSet(preparedStatementQuery)) {
ResultSet resultSet = preparedStatement.executeQuery();
rowSet = new CachedRowSetImpl();
rowSet.populate(resultSet);
resultSet.close();
} else if (SQLHelper.isWriteQuery(preparedStatementQuery)) {
preparedStatement.executeUpdate();
} else {
throw new Exception("Query does not return a ResultSet and is not a write query ("+preparedStatementQuery+")");
}
} finally {
if (preparedStatement!=null) preparedStatement.close();
if (connection != null) connectionPool.freeConnection(connection);
}
return rowSet;
}
这一行有问题Connection connection = connectionPool.getConnection();
如果我将其更改为 Connection connection = null;
- 不会发生异常。
我的问题是为什么?我所做的只是重新分配 try
块中的连接。或者每当调用 ConnectionPool.getConnection()
时,它都会打开一个新连接,而不管在同一个对象上调用哪个连接,都会打开一个旧连接?
为方便起见的完整堆栈跟踪:
ERROR : 2015-12-08 13:16:46 [com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController-] org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:104)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at alchimea.utils.sql.DBCP_ConnectionPool.getConnection(DBCP_ConnectionPool.java:36)
at alchimea.utils.sql.BasicSQLDataSource.executePreparedStatement(BasicSQLDataSource.java:288)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.setCompanyTravellerType(SapHrImportUserDataObjectReconciler.java:444)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.translateSapHrUserDataObjectToContactPerson(SapHrImportUserDataObjectReconciler.java:410)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateContactPerson(SapHrImportUserDataObjectReconciler.java:266)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateSapUserDetails(SapHrImportUserDataObjectReconciler.java:62)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:116)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1134)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96)
... 52 more
Send Email
From: it@wings.travel
To: bugs@gotraveltech.com
Subject: java.util.NoSuchElementException:Timeout waiting for idle object on server: 1
Body:
There has been an Exception on server 1.
Please plan time to fix this.
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:104)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at alchimea.utils.sql.DBCP_ConnectionPool.getConnection(DBCP_ConnectionPool.java:36)
at alchimea.utils.sql.BasicSQLDataSource.executePreparedStatement(BasicSQLDataSource.java:288)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.setCompanyTravellerType(SapHrImportUserDataObjectReconciler.java:444)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.translateSapHrUserDataObjectToContactPerson(SapHrImportUserDataObjectReconciler.java:410)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateContactPerson(SapHrImportUserDataObjectReconciler.java:266)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateSapUserDetails(SapHrImportUserDataObjectReconciler.java:62)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:116)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1134)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96)
... 52 more
java.lang.Exception: [SapHrImportController][processFile]org.apache.commons.dbcp.SQLNestedException
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:104)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at alchimea.utils.sql.DBCP_ConnectionPool.getConnection(DBCP_ConnectionPool.java:36)
at alchimea.utils.sql.BasicSQLDataSource.executePreparedStatement(BasicSQLDataSource.java:288)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.setCompanyTravellerType(SapHrImportUserDataObjectReconciler.java:444)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.translateSapHrUserDataObjectToContactPerson(SapHrImportUserDataObjectReconciler.java:410)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateContactPerson(SapHrImportUserDataObjectReconciler.java:266)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateSapUserDetails(SapHrImportUserDataObjectReconciler.java:62)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:116)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1134)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96)
... 52 more
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:127)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.Authen
ticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
您正在获取新的数据库连接两次。第一次在该行中您自己将其标记为有问题的行。此连接未释放。相反,您直接获取另一个连接,然后在 finally 块中使用并正确释放该连接。但是,您检索到的第一个连接仍保留在服务器上。由于服务器的可用连接数量有限,有时您会收到无法获取另一个连接的异常。
通过在首次定义时将连接变量设置为 null
来解决问题(正如您自己建议的那样)。
我通过调用波纹管方法 48 次 +/-
得到了上述异常public ResultSet executePreparedStatement(String preparedStatementQuery, List<?> parameters) throws Exception {
CachedRowSetImpl rowSet = null;
PreparedStatement preparedStatement = null;
Connection connection = connectionPool.getConnection(); // The problem is with this line
try {
connection = connectionPool.getConnection();
preparedStatement = connection.prepareStatement(preparedStatementQuery);
for (int i=0;i<parameters.size();i++) {
preparedStatement.setObject(i+1, parameters.get(i));
}
if (SQLHelper.doesQueryReturnsResultSet(preparedStatementQuery)) {
ResultSet resultSet = preparedStatement.executeQuery();
rowSet = new CachedRowSetImpl();
rowSet.populate(resultSet);
resultSet.close();
} else if (SQLHelper.isWriteQuery(preparedStatementQuery)) {
preparedStatement.executeUpdate();
} else {
throw new Exception("Query does not return a ResultSet and is not a write query ("+preparedStatementQuery+")");
}
} finally {
if (preparedStatement!=null) preparedStatement.close();
if (connection != null) connectionPool.freeConnection(connection);
}
return rowSet;
}
这一行有问题Connection connection = connectionPool.getConnection();
如果我将其更改为 Connection connection = null;
- 不会发生异常。
我的问题是为什么?我所做的只是重新分配 try
块中的连接。或者每当调用 ConnectionPool.getConnection()
时,它都会打开一个新连接,而不管在同一个对象上调用哪个连接,都会打开一个旧连接?
为方便起见的完整堆栈跟踪:
ERROR : 2015-12-08 13:16:46 [com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController-] org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:104)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at alchimea.utils.sql.DBCP_ConnectionPool.getConnection(DBCP_ConnectionPool.java:36)
at alchimea.utils.sql.BasicSQLDataSource.executePreparedStatement(BasicSQLDataSource.java:288)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.setCompanyTravellerType(SapHrImportUserDataObjectReconciler.java:444)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.translateSapHrUserDataObjectToContactPerson(SapHrImportUserDataObjectReconciler.java:410)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateContactPerson(SapHrImportUserDataObjectReconciler.java:266)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateSapUserDetails(SapHrImportUserDataObjectReconciler.java:62)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:116)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1134)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96)
... 52 more
Send Email
From: it@wings.travel
To: bugs@gotraveltech.com
Subject: java.util.NoSuchElementException:Timeout waiting for idle object on server: 1
Body:
There has been an Exception on server 1.
Please plan time to fix this.
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:104)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at alchimea.utils.sql.DBCP_ConnectionPool.getConnection(DBCP_ConnectionPool.java:36)
at alchimea.utils.sql.BasicSQLDataSource.executePreparedStatement(BasicSQLDataSource.java:288)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.setCompanyTravellerType(SapHrImportUserDataObjectReconciler.java:444)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.translateSapHrUserDataObjectToContactPerson(SapHrImportUserDataObjectReconciler.java:410)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateContactPerson(SapHrImportUserDataObjectReconciler.java:266)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateSapUserDetails(SapHrImportUserDataObjectReconciler.java:62)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:116)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1134)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96)
... 52 more
java.lang.Exception: [SapHrImportController][processFile]org.apache.commons.dbcp.SQLNestedException
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:104)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at alchimea.utils.sql.DBCP_ConnectionPool.getConnection(DBCP_ConnectionPool.java:36)
at alchimea.utils.sql.BasicSQLDataSource.executePreparedStatement(BasicSQLDataSource.java:288)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.setCompanyTravellerType(SapHrImportUserDataObjectReconciler.java:444)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.translateSapHrUserDataObjectToContactPerson(SapHrImportUserDataObjectReconciler.java:410)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateContactPerson(SapHrImportUserDataObjectReconciler.java:266)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportUserDataObjectReconciler.updateSapUserDetails(SapHrImportUserDataObjectReconciler.java:62)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:116)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1134)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96)
... 52 more
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.processFile(SapHrImportController.java:127)
at com.gotraveltech.hotswap.custom.wings.halliburton.SapHrImportController.process(SapHrImportController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at alchimea.utils.hotswap.DynamicObjectLoader.invoke(DynamicObjectLoader.java:338)
at org.apache.commons.proxy.ProxyFactory$InvokerInvocationHandler.invoke(ProxyFactory.java:255)
at com.sun.proxy.$Proxy118.process(Unknown Source)
at org.apache.jsp.contactList.externalPeople.sapFileImporter.sapFileUploader_jsp._jspService(sapFileUploader_jsp.java:788)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.applicationFilter.TmaApplicationFilter.doFilter(TmaApplicationFilter.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.filter.ApplicationLoaderFilter.doFilter(ApplicationLoaderFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at alchimea.aqua.CharsetFilter.doFilter(CharsetFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.Authen
ticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
您正在获取新的数据库连接两次。第一次在该行中您自己将其标记为有问题的行。此连接未释放。相反,您直接获取另一个连接,然后在 finally 块中使用并正确释放该连接。但是,您检索到的第一个连接仍保留在服务器上。由于服务器的可用连接数量有限,有时您会收到无法获取另一个连接的异常。
通过在首次定义时将连接变量设置为 null
来解决问题(正如您自己建议的那样)。