Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Undeploying web application does not stop the running process

 
Veera Sundar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Veera Sundar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic