Tomcat连接池ThrowableCallStack问题

时间:2018-11-16 13:10:47

标签: tomcat connection-pooling tomcat8.5

有时在Tomcat8.5中找到以下日志。当我们观察到错误 stacktrace我们没有在代码中找到任何连接泄漏,但是日志 有时会被捕获。我无法识别这是否是 连接泄漏或任何其他问题的指示。

Pooled object created 2018-11-13 11:00:01 -0800 by the following code
has not been returned to the pool:
org.apache.tomcat.dbcp.pool2.impl.ThrowableCallStack$Snapshot   at
org.apache.tomcat.dbcp.pool2.impl.ThrowableCallStack.fillInStackTrace(ThrowableCallStack.java:71)
        at org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject.allocate(DefaultPooledObject.java:192)
        at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:455)
        at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361)
        at org.apache.tomcat.dbcp.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134)
        at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1543)
        at com.sample.test.db.SlaveDBConnection.initiateConnection(SlaveDBConnection.java:40)
        at com.sample.test.db.SlaveDBConnection.<init>(SlaveDBConnection.java:25)
        at com.sample.test.db.DBFactory.getDBObject(DBFactory.java:80)
        at com.sample.test.app.model.dao.UserDAOImpl.getUserData(UserDAOImpl.java:1795)
        at org.apache.jsp.getData_jsp._jspService(getData_jsp.java:298)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.MFilter.doFilter(MFilter.java:52)

这是什么意思 org.apache.tomcat.dbcp.pool2.impl.ThrowableCallStack$Snapshot以及何时 我们得到这个问题吗?以及我们如何重现此问题?

1 个答案:

答案 0 :(得分:1)

您正在运行的Web应用程序已为资源池激活logAbandoned标志。每当应用程序获取新的JDBC连接时,池将花费(开销)时间并将调用堆栈跟踪记录在内存中。 以后只要发现JDBC连接未正确关闭,它就会获取该堆栈跟踪快照并将其转储到日志中,指向获取连接的确切位置(Java源文件和行,如果为调试而编译)。尚未安全关闭,可能会导致连接泄漏。

可重复性在很大程度上取决于应用程序实际执行的操作和时间。如果有很多附带条件可能很难再现,但是您可以从堆栈跟踪中读取它的实际位置来读取它的实际位置,并可以分析源代码,找到有罪的代码行,甚至可以怪罪于开发人员;-)

See the Tomcat documentation for further reading here