2012-06-09 93 views
0

过去四天,我在Tomcat停止响应的生产服务器上遇到问题,以及当我尝试通过shutdow.sh关闭它时,tomcat进程仍然活着。我将不得不杀死进程并重新启动。 下面的堆栈会在tomcat崩溃之前直接记录并停止响应。我做了很多研究,但还没有解决问题。Tomcat停止响应,无法关闭

任何帮助表示赞赏

有两次严重的web应用程序错误

Jun 9, 2012 4:50:08 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 
SEVERE: The web application [/beta] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
Jun 9, 2012 4:50:08 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: The web application [/beta] appears to have started a thread named [MultiThreadedHttpConnectionManager cleanup] but has failed to stop it. This is very likely to create a memory leak. 

与一个MySQL错误下面

INFO: Illegal access: this web application instance has been stopped already. Could not load com.mysql.jdbc.SQLError. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. 
java.lang.IllegalStateException 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1587) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546) 
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3358) 
    at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1695) 
    at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4388) 
    at com.mysql.jdbc.ConnectionImpl.cleanup(ConnectionImpl.java:1368) 
    at com.mysql.jdbc.ConnectionImpl.finalize(ConnectionImpl.java:2737) 
    at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method) 
    at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83) 
    at java.lang.ref.Finalizer.access$100(Finalizer.java:14) 
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160) 

完整的堆栈

INFO: Destroying Spring FrameworkServlet 'springMvcServlet' 
Jun 9, 2012 4:50:08 PM org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
Jun 9, 2012 4:50:08 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 
SEVERE: The web application [/beta] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
Jun 9, 2012 4:50:08 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: The web application [/beta] appears to have started a thread named [MultiThreadedHttpConnectionManager cleanup] but has failed to stop it. This is very likely to create a memory leak. 
Jun 9, 2012 4:50:09 PM org.apache.catalina.loader.WebappClassLoader validateJarFile 
INFO: validateJarFile(/home/bratecp/public_html/beta/WEB-INF/lib/ImageEditor.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class 
Jun 9, 2012 4:50:09 PM org.apache.catalina.loader.WebappClassLoader validateJarFile 
INFO: validateJarFile(/home/bratecp/public_html/beta/WEB-INF/lib/gwt-user.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class 
Jun 9, 2012 4:50:09 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
Jun 9, 2012 4:50:11 PM org.apache.catalina.loader.WebappClassLoader loadClass 
INFO: Illegal access: this web application instance has been stopped already. Could not load com.mysql.jdbc.SQLError. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. 
java.lang.IllegalStateException 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1587) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546) 
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3358) 
    at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1695) 
    at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4388) 
    at com.mysql.jdbc.ConnectionImpl.cleanup(ConnectionImpl.java:1368) 
    at com.mysql.jdbc.ConnectionImpl.finalize(ConnectionImpl.java:2737) 
    at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method) 
    at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83) 
    at java.lang.ref.Finalizer.access$100(Finalizer.java:14) 
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160) 
Jun 9, 2012 4:58:44 PM org.apache.catalina.core.AprLifecycleListener init 
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.6.0_29/jre/lib/amd64/server:/usr/local/jdk1.6.0_29/jre/lib/amd64:/usr/local/jdk1.6.0_29/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 
Jun 9, 2012 4:58:44 PM org.apache.catalina.startup.SetAllPropertiesRule begin 
WARNING: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'compression' to 'on' did not find a matching property. 
Jun 9, 2012 4:58:44 PM org.apache.catalina.startup.SetAllPropertiesRule begin 
WARNING: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'compressionMinSize' to '2048' did not find a matching property. 
Jun 9, 2012 4:58:44 PM org.apache.catalina.startup.SetAllPropertiesRule begin 
WARNING: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'noCompressionUserAgents' to 'gozilla, traviata' did not find a matching property. 
Jun 9, 2012 4:58:44 PM org.apache.catalina.startup.SetAllPropertiesRule begin 
WARNING: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'compressableMimeType' to 'text/xml,text/plain,application/json,application/javascript,text/css' did not find a matching property. 
Jun 9, 2012 4:58:44 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property. 
Jun 9, 2012 4:58:44 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property. 
Jun 9, 2012 4:58:44 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property. 
Jun 9, 2012 4:58:45 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Jun 9, 2012 4:58:45 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Jun 9, 2012 4:58:45 PM org.apache.catalina.startup.Catalina load 

回答

2

疗法e为同时出现至少两个问题:

  1. 您要注册正在从加载你的web应用的WEB-INF/lib目录中的JDBC驱动程序和失败时,你的web应用关闭注销驱动程序。您可以使用ServletContextListener中的java.sql.DriverManager.deregisterDriver()轻松取消注册JDBC驱动程序。

  2. 你(有可能)有一个非守护线程超出你的web应用程序。确定发生什么的唯一方法是进行线程转储以找出哪个线程仍然存在(在运行shutdown.sh并等待5秒钟以等待所有事情安定下来)以及它可能来自哪里。基本上,当你的web应用程序关闭时,无论你在web应用程序中启动哪个线程,都需要有一个对称的停止线程。请记住,某些操作在您没有意识到的情况下启动线程(例如,创建TimerTask,执行某些AWT相关的操作等)。

你可能想解决这两个问题,以提高应用程序服务器的稳定性。

在上面的堆栈跟踪中,它是一个连接终结器,它试图“真正”关闭与数据库的连接。我想知道,在你的webapp关闭之前,你是不是正确地关闭了你的Connection对象(或者连接池),所以Connection终结器在他们实际完成目标之后(在ClassLoader死掉之后)运行。

+0

会将mysql连接器jar放在tomcat lib中,并从我的应用程序库中删除jar将解决问题1?对于第二个问题,它会连接MultiThreadedHttpConnectionManager有内存泄漏并导致最终冻结tomcat的OutOfMemoryError。我添加了MultiThreadedHttpConnectionManager.shutdownAll();在我的ServletContextListener中。我仍然在测试,但不知道。我的解决方案的任何意见? –

+0

如果您认为MultiThreadedHttpConnectionManager存在缺陷,您应该与apache-commons人员交谈:他们可以帮助修复它(并且可能已经使用比您使用的版本更新的版本)。根据问题的真实性,将Connector/J放入Tomcat的lib目录*可能会工作。 –

+0

我加了MultiThreadedHttpConnectionManager.shutdownAll();在我的ServletContextListener.contextDestroyed中,并将mysql连接器jar移动到tomcat lib。这个应用程序已经运行了3天,工作正常,没有任何泄漏...... –