Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

destroy() method not called on server redeploy

843841Nov 18 2007 — edited Nov 19 2007
Hi everyone, I hope this is the right forum to be posting this question in.

I am running a web server with Apache Tomcat 5.5.23. In the web.xml file I have specified a servlet to be loaded on startup using the load-on-startup parameter:
<servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>com.example.MyServlet</servlet-class>
        <load-on-startup/>
    </servlet>
In the init() method of MyServlet I do some server initialization (warming up the database, etc.). One of the things I initialize is a socket which listens for multicast messages. The problem I'm having is that on server redeploy, the servlet's destroy() method isn't being called so I can't kill the thread which is listening for multicast, so when the server redeploys the message gets received and processed twice.

It's a very strange problem because it only happens the first time I redeploy; on subsequent redeploys, the destroy() method gets called fine. Therefore, after redeploying I always have exactly two threads listening for multicast: the one from the very first server context when the server was started the first time, and the most recent one.

I'm looking for one of two possible solutions. I would either like to be able to have my servlet be properly destroyed on redeploy, or I would like to put the multicast initialization in a different part of the application. However, it has to be somewhere that is guaranteed to be called when Tomcat starts.

Thanks for any suggestions you can offer, if you need more information about my setup just ask.

Mark
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2007
Added on Nov 18 2007
5 comments
312 views