tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Konstantin Kolinko (JIRA)" <>
Subject [jira] [Commented] (MTOMCAT-186) Closing executable JAR does not call ServletContextListener.contextDestroyed()
Date Sun, 02 Dec 2012 21:27:58 GMT


Konstantin Kolinko commented on MTOMCAT-186:

The shutdown hook used by o.a.c.startup.Catalina is Catalina$CatalinaShutdownHook.  Maybe
it could be generalized, or a similar class should be added to be used with o.a.c.startup.Tomcat.

If someone is going to create a copy of the shutdown hook class, maybe I should explain one
implementation detail:

Note that the logging subsystem installs its own shutdown hook as well.  When JVM shuts down,
it starts all hooks in parallel without any order, so there is a risk that some log messages
will be lost as the logging system will be shut down too early.

This issue is already solved in Catalina$CatalinaShutdownHook, but the solution works only
when Tomcat's JULI ClassLoaderLogManager is used.  It does not work with plain java.util.logging.LogManager
which I think is used when running a JAR file.

I see that Tomcat7Runner.installLogger() may install "org.slf4j.bridge.SLF4JBridgeHandler".
I do not know how to deal with that one either.

The solution works like the following:

First, it should be noted that the following 3 hooks are installed:
a) java.util.logging.LogManager$Cleaner
b) org.apache.juli.ClassLoaderLogManager$Cleaner
c) org.apache.catalina.startup.Catalina$CatalinaShutdownHook

To ensure that the logging subsystem is shutdown by CatalinaShutdownHook only, the following
is used:

1. "a)" is dealt with in ClassLoaderLogManager.reset() where it ignores a call from LogManager$Cleaner
2. "b)" is dealt with in Catalina.start() where it calls ClassLoaderLogManager.setUseShutdownHook(false)
after installing its own shutdown hook
3.  Catalina$ calls ClassLoaderLogManager.shutdown()
> Closing executable JAR does not call ServletContextListener.contextDestroyed()
> ------------------------------------------------------------------------------
>                 Key: MTOMCAT-186
>                 URL:
>             Project: Apache Tomcat Maven Plugin
>          Issue Type: Bug
>          Components: tomcat7
>    Affects Versions: 2.0
>         Environment: Java 7, maven 3.0.3
>            Reporter: Tomasz Nurkiewicz
>            Assignee: Olivier Lamy (*$^¨%`£)
>            Priority: Minor
>             Fix For: 2.1
>         Attachments:
> Executable JAR created by {{tomcat7-maven-plugin:exec-war-only}} does not call {{ServletContextListener.contextDestroyed()}}
callback method when Java process is killed or when Ctrl + C is pressed. There is no way (?)
to cleanly shutdown web application.
> The same application (attached) deployed on standalone Tomcat works just fine. Hitting
Ctrl + C correctly undeploys and shuts down application.
> Build attached application and run {{java -jar target/standalone.jar}}. Ctrl + C kills
the process immediately. On the other hand {standalone.war}} deployed to normal Tomcat under
{{/webapps}} shuts down correctly and we can see log statement from {{contextDestroyed()}}.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message