[GLASSFISH-17416] Add configurable delay to servlet container shutdown process. Created: 12/Oct/11  Updated: 07/Mar/12

Status: Open
Project: glassfish
Component/s: web_container
Affects Version/s: 3.1.1
Fix Version/s: None

Type: New Feature Priority: Critical
Reporter: psprague Assignee: Shing Wai Chan
Resolution: Unresolved Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


The version of tomcat GlassFish's servlet container is based on doesn't allow us to configure a delay before unloading the servlets. Since the threads are set as daemon threads the JVM simply stops them. This means when we try and do a graceful shutdown (asadmin stop-domain --force=false) in-flight requests are killed before they complete.


public synchronized void unload() throws ServletException {

        // Nothing to do if we have never loaded the instance
        if (!singleThreadModel && (instance == null))
        unloading = true;

        // Loaf a while if the current instance is allocated
        // (possibly more than once if non-STM)
        if (countAllocated > 0) {
            int nRetries = 0;
            while ((nRetries < 21) && (countAllocated > 0)) {
                if ((nRetries % 10) == 0) {
                    if (log.isLoggable(Level.FINE)) {
                try {
                } catch (InterruptedException e) {
                    // Ignore


In Tomcat 6 this method has been changed to support a configurable unload delay.

I would also like to point out that the documentation for asadmin stop-domain states that --force=false waits for threads to complete; while this appears to be true for the EJB container it is not true for the servlet container.


         Specifies whether the domain is forcibly stopped immedi-

         Possible values are as follows:

             The   domain   is   forcibly   stopped   immediately

             The subcommand waits  until  all  threads  that  are
             associated  with  the domain are exited before stop-
             ping the domain.


Comment by Shing Wai Chan [ 06/Jan/12 ]

Port Tomcat change: http://svn.apache.org/viewvc?view=revision&revision=345286

Sending web-core/src/main/java/org/apache/catalina/core/StandardContext.java
Sending web-core/src/main/java/org/apache/catalina/core/StandardWrapper.java
Transmitting file data ..
Committed revision 51916.

Comment by craigwblake [ 07/Mar/12 ]

Does the commit mean that this has been resolved? If so, what release can we expect this in?


Generated at Sun Nov 29 16:44:12 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.