Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Undeploying web application does not stop the running process

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Create symphonies in seed and soil. For this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic