aspose file tools*
The moose likes Threads and Synchronization and the fly likes Undeploying web application does not stop the running process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Undeploying web application does not stop the running process" Watch "Undeploying web application does not stop the running process" New topic
Author

Undeploying web application does not stop the running process

Veera Sundar
Greenhorn

Joined: Jun 08, 2007
Posts: 25
Hello Everyone,

Could you please help me in figuring out the following problem.

"I am running a web application, which will constantly monitor a ftp folder and whenever a new file comes on that folder, the application will download it. I have scheduled a thread to run every 15 mins to do this task. The problem, when I undeploy my web application from Tomcat, the scheduled process is not closing. It is still running."

Any clue on how to destroy this scheduled process while undeploying the web application?

Thanks.


Thanks,<br />Veera |<a href="http://veerasundar.com/blog" target="_blank" rel="nofollow">Blog</a>
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

If you are just spawning a new thread from inside your web application, Tomcat will not be able to interrupt it when the web app is undeployed.
May be you can ask the question in Tomcat forum, they will be able to tell whether you can attach a hook to get a callback on webapp undeployment.


apigee, a better way to API!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
In order to terminate threads you need to stop them from your code. Generally this is done by having the loop in the Thread periodically the value of a boolean, which can be set from outside of the trhead.

Alternatively, you could use the java.util.Timer and TimerTask classes -instead of dealing with Thread or Runnable-; those will be terminated if the web app is shut down.


Ping & DNS - my free Android networking tools app
Veera Sundar
Greenhorn

Joined: Jun 08, 2007
Posts: 25
@Nitesh

I will post this question in Tomcat forum. Thanks for the suggestion. :-)


@Ulf

I am using the TimerTask class, but still I'm having the problem.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
I am using the TimerTask class, but still I'm having the problem.

Are you specifying that the Timer should be run as a daemon in the constructor? That's required to be able to shut it down.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Veera Sundar I will post this question in Tomcat forum. Thanks for the suggestion. :-)[/QB]


Oops, sorry dont do that. This is not correct according to this javaranch policy. Moderators may do this, if they think that this is not the correct forum for this question.

Ulf: Are you specifying that the Timer should be run as a daemon in the constructor? That's required to be able to shut it down.

Ulf, correct me if i am wrong, marking it as Daemon will make the JVM exit when only daemon threads are running. Does Tomcat keeps an account as to which thread is created by which webapp and interrupt it when that webapp is stopped/undeployed?
[ January 11, 2008: Message edited by: Nitesh Kant ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Non daemon threads will keep the JVM alive until they're done processing which can be problematic in an environment like a web server.

Making them daemon might not be enough to stop them when an application is stopped (but Tomcat is not). You should, as Ulf mentioned have code that is executed when the web application is shutdown that interrupts the thread.

How are you kicking off the thread in Tomcat?
Are you using a contextListener?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Consider Paul's rocket mass heater.
 
subject: Undeploying web application does not stop the running process