You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daniel Savard <da...@gmail.com> on 2016/03/17 00:40:01 UTC

contextDestroyed() method not called

Hi everyone,

I noticed a problem with one of my web applications which requires
some cleanup when shutdown. It seems this cleanup isn't happening even
if everything has been put in the contextDestroyed() method of my web
listener. So, to debug this problem I wrote a minimal web listener and
tested to see what is going on. It seems the contextDestroyed() method
isn't called when stopping the web application or stopping the Tomcat
instance.

Here is my minimal code:

package some.thing;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@WebListener
public class TestContext implements ServletContextListener {

private Logger log = LogManager.getLogger();

public TestContext() {
     log.info("Constructor");
}

@Override
public void contextDestroyed(ServletContextEvent arg0) {
      log.info("Context destroyed.");
}

@Override
public void contextInitialized(ServletContextEvent arg0) {
      log.info("Context initialized.");
}

}

The constructor's info and the contextInitialized() info are both
written to my log file, the info from the contextDestroyed() method is
missing.

I am running Tomcat 8.0.32 with Java 1.8.0.74, but I have seen a
similar behavior with Tomcat 6.0.24 and Java 1.6.0.91 as well. I am
using log4j 2.5.

I find it difficult to believe this is a bug in Tomcat, so, I guess I
am doing something wrong. Someone can provide some guidance to
identify the cause of such undesirable behavior?

Regards,
-----------------
Daniel Savard

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: contextDestroyed() method not called

Posted by Daniel Savard <da...@gmail.com>.
Nevermind, the contextDestroyed() method is actually called as
supposed and expected. The problem seems the logger is no longer able
to output anything in the log file at this point even if I configured
it to flush immediately the output. I replaced the log.info()
statement by a System.out.println() followed by a System.out.flush()
and I can see the output.

However, it seems the context is destroyed before my objects are
themselves destroyed since I still receive messages in the
catalina.out about them, like this one:

INFOS: Closing Spring root WebApplicationContext
Destruction du contexte applicatif. Application: CaissesDispo,
Serveur: Apache Tomcat/8.0.32_ds
Désinscrit les écouteurs de requêtes uCMDB.
Détruit le bassin de connexions uCMDB.
Application: CaissesDispo terminée.
mars 17, 2016 7:44:15 PM
org.apache.catalina.loader.WebappClassLoaderBase
clearReferencesThreads
AVERTISSEMENT: The web application [CaissesDispo] appears to have
started a thread named [UCMDB Model Notifications Service Notification
Thread] but has failed to stop it. This is very likely to create a
memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
 com.hp.ucmdb.api.client.topology.notification.AbstractNotificationService$NotifyListeners.run(AbstractNotificationService.java:244)
 java.lang.Thread.run(Thread.java:745)
mars 17, 2016 7:44:15 PM
org.apache.catalina.loader.WebappClassLoaderBase
clearReferencesThreads


Anything can be done to avoid these messages if the objects are
actually destroyed?

-----------------
Daniel Savard


2016-03-17 19:08 GMT-04:00 Daniel Savard <da...@gmail.com>:
> From the manager clicking on the Stop button for the application. For
> the instance, on Windows just stop the Tomcat service, on Linux, just
> run the catalina.sh stop script.
> -----------------
> Daniel Savard
>
>
> 2016-03-17 8:47 GMT-04:00 Caldarale, Charles R <Ch...@unisys.com>:
>>> From: Daniel Savard [mailto:daniel.savard@gmail.com]
>>> Subject: Re: contextDestroyed() method not called
>>
>> Read the mailing list rules: don't top post.
>> http://tomcat.apache.org/lists.html#tomcat-users
>>
>>> I'm running it on Window 2012 Server as well as Linux RHEL.
>>
>> Ok, good to know.
>>
>>> And no, I am not sending a terminate signal with kill -9. That's why I
>>> said I am stopping the application or the instance (both cases depict
>>> the same behavior) rather than saying I am terminating it.
>>
>> Again, how are you doing this?
>>
>>  - Chuck
>>
>>
>> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: contextDestroyed() method not called

Posted by Daniel Savard <da...@gmail.com>.
>From the manager clicking on the Stop button for the application. For
the instance, on Windows just stop the Tomcat service, on Linux, just
run the catalina.sh stop script.
-----------------
Daniel Savard


2016-03-17 8:47 GMT-04:00 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Daniel Savard [mailto:daniel.savard@gmail.com]
>> Subject: Re: contextDestroyed() method not called
>
> Read the mailing list rules: don't top post.
> http://tomcat.apache.org/lists.html#tomcat-users
>
>> I'm running it on Window 2012 Server as well as Linux RHEL.
>
> Ok, good to know.
>
>> And no, I am not sending a terminate signal with kill -9. That's why I
>> said I am stopping the application or the instance (both cases depict
>> the same behavior) rather than saying I am terminating it.
>
> Again, how are you doing this?
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: contextDestroyed() method not called

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Daniel Savard [mailto:daniel.savard@gmail.com] 
> Subject: Re: contextDestroyed() method not called

Read the mailing list rules: don't top post.
http://tomcat.apache.org/lists.html#tomcat-users

> I'm running it on Window 2012 Server as well as Linux RHEL.

Ok, good to know.

> And no, I am not sending a terminate signal with kill -9. That's why I
> said I am stopping the application or the instance (both cases depict
> the same behavior) rather than saying I am terminating it.

Again, how are you doing this?

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: contextDestroyed() method not called

Posted by Daniel Savard <da...@gmail.com>.
Hi Chuck,

I'm running it on Window 2012 Server as well as Linux RHEL.

And no, I am not sending a terminate signal with kill -9. That's why I
said I am stopping the application or the instance (both cases depict
the same behavior) rather than saying I am terminating it.

Regards,
-----------------
Daniel Savard


2016-03-16 23:56 GMT-04:00 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Daniel Savard [mailto:daniel.savard@gmail.com]
>> Subject: contextDestroyed() method not called
>
>> I noticed a problem with one of my web applications which requires
>> some cleanup when shutdown. It seems this cleanup isn't happening even
>> if everything has been put in the contextDestroyed() method of my web
>> listener.
>
>> I find it difficult to believe this is a bug in Tomcat, so, I guess I
>> am doing something wrong. Someone can provide some guidance to
>> identify the cause of such undesirable behavior?
>
> Missing a couple useful bits of information:
>
> 1) What OS are you running on?
>
> 2) More importantly, how are you shutting down Tomcat?  (Using kill -9 would not be a good choice...)
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: contextDestroyed() method not called

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Daniel Savard [mailto:daniel.savard@gmail.com] 
> Subject: contextDestroyed() method not called

> I noticed a problem with one of my web applications which requires
> some cleanup when shutdown. It seems this cleanup isn't happening even
> if everything has been put in the contextDestroyed() method of my web
> listener.

> I find it difficult to believe this is a bug in Tomcat, so, I guess I
> am doing something wrong. Someone can provide some guidance to
> identify the cause of such undesirable behavior?

Missing a couple useful bits of information:

1) What OS are you running on?

2) More importantly, how are you shutting down Tomcat?  (Using kill -9 would not be a good choice...)

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org