Tomcat cannot shutdown process problem resolution

Source: Internet
Author: User
1 Problem Phenomena

After executing shutdown.sh, the web is no longer accessible:


The Tomcat associated Java process is still alive:

#/home/apache-tomcat-7.0.34/bin/shutdown.sh using catalina_base:/home/apache-tomcat-7.0.34 using CATALINA_HOME:/
home/apache-tomcat-7.0.34 using Catalina_tmpdir:/home/apache-tomcat-7.0.34/temp using jre_home:/home/jdk1.6.0_34 Using CLASSPATH:/home/apache-tomcat-7.0.34/bin/bootstrap.jar:/home/apache-tomcat-7.0.34/bin/tomcat-juli.jar # PS A UX | grep ' Java.*tomcat ' | grep-v grep root 22465 15.3 8.6 1294300 346264 pts/0 Sl 14:55 1:08/home/jdk1.6.0_34/bin/java-djava.util.loggi Ng.config.file=/home/apache-tomcat-7.0.34/conf/logging.properties-djava.util.logging.manager= org.apache.juli.classloaderlogmanager-djava.endorsed.dirs=/home/apache-tomcat-7.0.34/endorsed-classpath/home/ apache-tomcat-7.0.34/bin/bootstrap.jar:/home/apache-tomcat-7.0.34/bin/tomcat-juli.jar-dcatalina.base=/home/ Apache-tomcat-7.0.34-dcatalina.home=/home/apache-tomcat-7.0.34-djava.io.tmpdir=/home/apache-tomcat-7.0.34/temp Org.apache.catalina.startup.Bootstrap start
2013-1-8 15:02:53 Org.apache.catalina.loader.WebappClassLoader Clearreferencesjdbccatalina.out reported memory leak warning:

Serious: the Web application [] registered the JDBC driver [Com.mysql.jdbc.Driver] but failed to unregister it when the Web App Lication was stopped.
To prevent a memory leak, the JDBC Driver has been, forcibly. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [Thread-2] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [Thread-snatch-picture] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [xmemcached-reactor-0] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 Org.apache.catalina.loader.WebappCLassloader clearreferencesthreads Severity: The Web application [] appears to have started a thread named [xmemcached-reactor-1] But has failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [Xmemcached-reactor-2] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [xmemcached-reactor-3] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [xmemcached-reactor-4] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 Org.apache.catalina.loader.WebappClassLoader CLearreferencesthreads severity: The Web application [] appears to have started a thread named [xmemcached-reactor-5] but has FAI led to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [xmemcached-reactor-6] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [xmemcached-reactor-7] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [Heal-session-thread] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 Org.apache.catalina.loader.WebappClassLoader clearreferenceSthreads severity: The Web application [] appears to have started a thread named [Pool-2-thread-1] but has to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [Pool-2-thread-2] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [pool-2-thread-3] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [pool-2-thread-4] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: the Web application [] appears to have started a thread named [Timer-0] but has-failed to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader clearreferencesthreads severity: The Web application [] Appears to have started a thread named [MySQL Statement cancellation Timer] but has to stop it.
This is very likely to create a memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader checkthreadlocalmapforleaks severity: The Web application [] Created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.containerimpl$10] (value [ COM.OPENSYMPHONY.XWORK2.INJECT.CONTAINERIMPL$10@B6C562]) and a value of type [java.lang.object[]] (value [[ LJAVA.LANG.OBJECT;@1D97383]) but failed to remove it when the Web application is stopped.
Threads are going to is renewed over time to try and avoid a probable memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader checkthreadlocalmapforleaks severity: The Web application []Created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.containerimpl$10] (value [ COM.OPENSYMPHONY.XWORK2.INJECT.CONTAINERIMPL$10@B6C562]) and a value of type [java.lang.object[]] (value [[ LJAVA.LANG.OBJECT;@9A827]) but failed to remove it when the Web application is stopped.
Threads are going to is renewed over time to try and avoid a probable memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader checkthreadlocalmapforleaks severity: The Web application [] Created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.containerimpl$10] (value [ COM.OPENSYMPHONY.XWORK2.INJECT.CONTAINERIMPL$10@B6C562]) and a value of type [java.lang.object[]] (value [[ LJAVA.LANG.OBJECT;@12E71F1]) but failed to remove it when the Web application is stopped.
Threads are going to is renewed over time to try and avoid a probable memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader checkthreadlocalmapforleaks severity: The Web application [] Created aThreadLocal with key of type [com.opensymphony.xwork2.inject.containerimpl$10] (value [ COM.OPENSYMPHONY.XWORK2.INJECT.CONTAINERIMPL$10@B6C562]) and a value of type [java.lang.object[]] (value [[ LJAVA.LANG.OBJECT;@855793]) but failed to remove it when the Web application is stopped.
Threads are going to is renewed over time to try and avoid a probable memory leak. 2013-1-8 15:02:53 org.apache.catalina.loader.WebappClassLoader checkthreadlocalmapforleaks severity: The Web application [] Created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.containerimpl$10] (value [ COM.OPENSYMPHONY.XWORK2.INJECT.CONTAINERIMPL$10@B6C562]) and a value of type [java.lang.object[]] (value [[ LJAVA.LANG.OBJECT;@5164DF]) but failed to remove it when the Web application is stopped. Threads are going to is renewed over time to try and avoid a probable memory leak.

2 Problem Analysis

This has not been encountered under Windows, because the previous run Tomcat is in the form of services rather than command scripts run, and has changed a project, so temporarily do not look at Windows under the existence of the problem.

Is it a tomcat version problem? or use Tomcat 7 with memory leak protection to resolve the problem. Attempts to run Web applications in apache-tomcat-6.0.18, apache-tomcat-6.0.35, apache-tomcat-7.0.34 have found that there is no shutdown.sh process problem.

In CentOS (Linux), Tomcat cannot stop the process with shutdown.sh. It's obviously impossible. Then the Web application removed from the WebApps, in return for Tomcat's own root, really started and then shutdown.sh, find the original Tomcat process, also proved to be the problem of their own web applications. 3 Solutions

Now that you have identified the problem with Web applications, you can make a solution. 3.1 Kill Process

Ignoring the critical warning in the log, because this is caused by shutting down Tomcat, this memory leak does not normally occur. and Tomcat6.18 above version of Tomcat has done a memory leak protection, to Tomcat completed it, we only need to shutdown.sh after a kill-9 PID can be made up. If this is too much trouble, you can change the following:

==============================bin/shutdown.sh 
Exec "$PRGDIR"/"$EXECUTABLE" Stop  -force "$@"  #加上-force  
 
==============================bin/catalina.sh  
prgdir= ' dirname ' after "$PRG" plus
if [-Z "$CATALINA _pid"]; Then
      catalina_pid= $PRGDIR/catalina_pid
      cat $CATALINA _pid
fi

To close a background thread in a 3.2 Web application

The reason for the Tomcat zombie process after shutdown.sh is that the shutdown.sh Web application does not shut down its enabled background threads, so the way to do this is to shut down its enabled background threads when hearing the Tomcat shutdown event.

Pstree-p the thread tree of the PID printing process to view background threads that are not closed after shutdown.sh:

Viewing active threads that are not closed after shutdown.sh through the Java VISUALVM

In Web applications, if you have a background thread, you can use shutdown.sh to turn off Tomcat. We need to rewrite the relevant Servletcontextlistener contextdestroyed (SERVLETCONTEXTEVENTARG0) method to close the background thread inside it.

However, many Web applications are now managed by spring to manage beans, and in practice we may need to inject a lot of beans from third-party jars. For example, in Applicationcontext.xml, configure the following bean:

<bean id = "DataSource" class = "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" >

In Org.apache.commons.dbcp.BasicDataSource, the logic of destroying the database thread pool needs to be done.

Of course we can also set the destruction logic ourselves. Add the listener in the Web.xml file.

<listener>
    <listener-class>com.mysite.MySpecialListener</listener-class>
</ Listener>
The Myspeciallistener implementation is as follows:

public class Myspeciallistener extends Applicationcontextlistener {@Override public void contextinitialized (SERVL Etcontextevent SCE) {//on application Startup, please ...//usually I ' ll make a singleton in, set up
    My pool, etc.
        @Override public void contextdestroyed (Servletcontextevent sce) {//on application Shutdown, ... 1.
        Go fetch the DataSource context Initcontext = new InitialContext ();
        Context Envcontext = (context) initcontext.lookup ("java:/comp/env");
        DataSource DataSource = (DataSource) envcontext.lookup ("Jdbc/database"); 2.
        Call "Close" () method on it Datasource.close (); 3. Deregister Driver try {java.sql.Driver mysqldriver = Drivermanager.getdriver ("Jdbc:mysql://localhost:
            3306/");
        Drivermanager.deregisterdriver (Mysqldriver); The catch (SQLException ex) {Logger.info ("Could not deregister driver:". ConcaT (Ex.getmessage ()));
    } DataSource = null;
 }
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.