File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes stopping and starting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "stopping and starting" Watch "stopping and starting" New topic

stopping and starting

Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
If you instantiate a Thread is it possible to keep interrupting and starting it with no consequences? I want to be able to re-start the run() method numerous times.
Martin webster

Joined: Jun 20, 2001
Posts: 20
From what I understand.. Once a thread is dead it is dead. You can't bring it back into the world of the living. You would have to create a new instance of the thread.

Yuri Gadow

Joined: May 08, 2001
Posts: 28
Once a run method is complete, the thread cannot be restarted, period. However, you can change the approach a bit to achieve the same effect. One (of many) ways is to have your run loop on a condition, wait on a shared monitor upon completion, and then use a notify to "restart" it - think work queue. I have some source I can post this evening if it would be helpful.
I agree. Here's the link:
subject: stopping and starting
It's not a secret anymore!