• Post Reply Bookmark Topic Watch Topic
  • New Topic

where to start..  RSS feed

 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can you please suggest where to start a daemon thread in web application?
I have a class which extends Thread. So id like to have this started ONCE when my webapplication starts.
I know it is possible to put in init() method of some servlet, so when user first time requests this servlet thread is started...
But my webapp uses Struts...
Thx in advance
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd recommend asking this in the Struts forum since it's really a Struts-specific question. I believe there is a standard place in web.xml that you can specify a certain servlet to start with the server, and then use its init() method to do what you want.

Note, however, that your particular container (for example, Tomcat) may not want you creating your own threads.

Also, as an unrelated design suggestion, you might want to have your class implement Runnable rather than extend Thread. This would allow you to hand it off to a ThreadPool and makes it more versatile, assuming you aren't overriding the behavior of the Thread itself. If all you do is override the run() method, there's no reason not to make it a Runnable.
 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx for reply
For some reason I forgot about web.xml
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!