• 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

background process on tomcat 4

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have 1 servlet which will run a thread, background process, whenever the init() on that servlet called. i tried on tomcat 3.3a and tomcat 3.2.3, and both tomcat will run my servlet's background process, will run the thread. but, when i run the servlet using tomcat 4, tomcat 4 will run the init(), but when it do not start the thread. what happen?... i used the same code, servlet, on tomcat 3.2.3, 3.3a and 4....
can anyone explain it to me?.....
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There should be no difference between the Tomcat versions with respect to running a "Background" Thread. What priority do you set for the Thread?
Bill
 
Ariffin Ahmad
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
There should be no difference between the Tomcat versions with respect to running a "Background" Thread. What priority do you set for the Thread?
Bill


well, i 'magically' work now...
but, i still can't understand why....
i used the same servlet, and the same web.xml on tomcat 3.2.3, 3.3a and 4.0.2....
but, i just notice, the higher priority in tomcat 4.0.2 is 1 not 0 as in 3.2.3 and 3.3a, is it true?.......
 
Ariffin Ahmad
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
There should be no difference between the Tomcat versions with respect to running a "Background" Thread. What priority do you set for the Thread?
Bill


and, what will happen to the background if i set the setDaemon(true)?.....
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will make your thread a daemon thread, i.e. a "helper" thread. It will die once the thread that spawns it dies. Please note you cannot call this method on a thread that has already started else it will throw an IllegalStateException.
-anthony
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NO NO NO - the following is totally wrong

Will make your thread a daemon thread, i.e. a "helper" thread. It will die once the thread that spawns it dies.


Where do these ideas get started???
Threads do not have the concept of a "parent" Thread. Daemon threads will die when the entire JVM is closed down or when they exit the run method like other Threads.
Bill
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, my mistake
A daemon thread dies when all user threads have stopped running, whether or not the daemon thread has finished its run() method. Of course, the daemon thread dies if it finishes its run() method earlier than that...
-anthony
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant 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