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!

How to stop Thread when tomcat shuts down

843841Jul 24 2007 — edited Jul 25 2007
Hi,

When I shut down tomcat, tomcat shuts down but the console window stays open and the system.out.prinln text from my class using Thread still shows.

Can I sense in my class if tomcat is still running? Or maby I call a method when tomcat stops to kill my thread?

In my web.xml I have the following code:
<servlet>
    	<servlet-name>Background Processor</servlet-name>
    	<servlet-class>src.com.business.Engine</servlet-class>
    	<load-on-startup>1</load-on-startup>
 </servlet>  
The Engine class is as follows:
public class Engine extends HttpServlet {

	public void init(ServletConfig config) throws ServletException {
      	super.init(config);

		CheckEndedItems checkEndedItems = CheckEndedItems.getInstance();
		checkEndedItems.start();
	}
}
The CheckEndedItems class implements Thread

Does someone know how I can stop this Thread when tomcat shuts down?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 22 2007
Added on Jul 24 2007
5 comments
631 views