• Post Reply Bookmark Topic Watch Topic
  • New Topic

Kicking off a thread from a servlet - please help!

 
James Kingston
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently writing a utility to do some performance monitoring on a Websphere instance. I have a job that collates the necessary values and writes them to a txt file. I want to be able to visit a PerformanceMonitor servlet which will in turn kick off the job.
The job - WritePropsFileRunner implements Runnable.
WritePropsFileRunner.run() runs a static class (WriteFile.class) that gets the information and writes to the file every 60 seconds. This is in an infinite loop.
When i call the WritePropsFileRunner class i use
WritePropsFileRunner wpfr = new WritePropsFileRunner();
wpfr.start("serverName","instanceName");
which in turn calls run()
Having not used threads before I was expecting this to kick off the thread in the background leaving my servlet to do what it wishes. But what actually happens is that the servlet just halts, looking as if it is waiting for the thread to finish.
basically what i am asking is "how do i start of a process (thread) to run in the background using a servlet".
Thanks in advance for your help.
james.
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When one implements Runnable, one starts another thread by creating an instance of Thread and calling start() on it:

Note that start() is called on the Thread, not on the RunnableImplementation. Thread will tell the VM to start up a new thread of execution which will in turn invoke RunnableImplementation.run().
 
James Kingston
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent. Thanks Joe. The notes i was reading on this subject did not make that clear at all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!