JDBC4Connection和Log4J

时间:2017-12-06 06:32:58

标签: java tomcat log4j blocked-threads

我正面临着tomcat7的高CPU使用率问题。使用JDK7开发的Web应用程序部署在tomcat服务器上。此Web应用程序联系在不同实例上运行的MySQL服务器,用于CRUD功能。

tomcat的CPU使用率在一周内变得异常高。为了分析它,我进行了线程转储,发现它是一些被阻塞的线程。

大多数被阻止的线程都有以下堆栈跟踪,

  

ajp-bio-8009-exec-20604 - 优先级:10 - threadId:0x0000000001aac000 -   nativeId:0x4143 - state:BLOCKED stackTrace:java.lang.Thread.State:   BLOCKED(在对象监视器上)at   org.apache.log4j.Category.callAppenders(Category.java:204)    - 等待锁定< 0x000000008bf42fc8> (org.apache.log4j.Logger)位于org.apache.log4j.Category.forcedLog(Category.java:391)at at   org.apache.log4j.Category.log(Category.java:838)at   com.myUtil.filter.XSSFilter.doFilter(XSSFilter.java:37)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)   在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)   在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)   在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)   在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)   在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)   在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)   在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)   在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)   在org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200)   在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:589)   在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:310)    - 已锁定< 0x00000000db84e148> (一个org.apache.tomcat.util.net.SocketWrapper)at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)   在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)   at java.lang.Thread.run(Thread.java:744)锁定的可拥有同步器:    - < 0x00000000db84e190> (java.util.concurrent.ThreadPoolExecutor $ Worker)

另一个与JDBC连接相关的堆栈跟踪

  

ajp-bio-8009-exec-20585 - 优先级:10 - threadId:0x000000000190f000 -   nativeId:0x40d6 - state:BLOCKED stackTrace:java.lang.Thread.State:   BLOCKED(在对象监视器上)at   com.mysql.jdbc.JDBC4Connection.isValid(JDBC4Connection.java:93)    - 等待锁定< 0x000000008bdf9890> (com.mysql.jdbc.JDBC4Connection)at   com.myUtil.dbconnection.DBAccessObject.IsConnected(DBAccessObject.java:751)   在   com.myUtil.dbhandler.MyDBHandler.InitOrGetConnection(MyDBHandler.java:119)   在   com.myUtil.dbhandler.MyDBHandler.GetNotification(MyDBHandler.java:8585)   在com.myUtil.util.ProcessRequest.myPost(ProcessRequest.java:1539)at   com.myUtil.util.ProcessRequest.doPost(ProcessRequest.java:104)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:647)at at   javax.servlet.http.HttpServlet.service(HttpServlet.java:728)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)   在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)   在com.myUtil.filter.XSSFilter.doFilter(XSSFilter.java:58)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)   在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)   在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)   在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)   在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)   在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)   在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)   在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)   在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)   在org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200)   在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:589)   在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:310)    - 已锁定< 0x00000000db7c38f8> (一个org.apache.tomcat.util.net.SocketWrapper)at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)   在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)   at java.lang.Thread.run(Thread.java:744)锁定的可拥有同步器:    - < 0x00000000db7c3940> (java.util.concurrent.ThreadPoolExecutor $ Worker)

我检查了MySQL服务器的状态。但是那里的一切(连接数/线程数)都很正常。

此应用程序在过去4年中运作良好。仅在过去的3个月里,我才面临这个问题。并且没有对服务器代码进行任何更改。每次发生此问题时,我都必须重新启动服务器。

如何找到此问题的根本原因并永久解决此问题?

0 个答案:

没有答案