I'm running a web application in Tomcat 7.0.53. I implement a ServletContextListener (call it InitListener) and correctly define it as a Listener in the web.xml:
<listener>
<description>listener that initializes common web app/service resources</description>
<listener-class>x.y.z.InitListener</listener-class>
</listener>
During the contextDestroyed event I would like to clean-up some code (e.g., shutdown a org.jboss.netty.channel.group.ChannelGroup using close ()), but my code always fails in this method with the error:
SEVERE: Exception sending context destroyed event to listener instance of class x.y.z.InitListener
java.lang.NoClassDefFoundError: org/jboss/netty/util/internal/ConcurrentHashMap$Values
Now, if I already use the ConcurrentHashMap$Values during the contextInitialized part of the InitListener by, e.g., calling close () on the ChannelGroup, then the shutdown works without problems.
It seems to me that during the contextDestroyed event Tomcat is not able to load the class any longer, but if it has been loaded beforehand, that there's no problem. But this can't be the solution, as I have other classes used in the contextDestroyed with the same problem. I would have to pre-load all classes I would like to use later on. Sounds like a hack to me.
What am I doing wrong? Why is Tomcat not able to load a new class any longer at this stage?
EDIT: As an additional information, the problem only occurs when I do a remote deployment of my web application. When I reload or undeploy the web application on the Tomcat it always shuts down gracefully. Just during remote deployment, the shutdown fails.
I just got an answer from the Tomcat developers. As Gimby already assumed, the problem was due to a bug in Tomcat. It is fixed in version 7.0.54 and higher.
Thanks for your help.