2012-06-09 126 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天,工作正常,沒有任何泄漏...... –