Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thread.stop() or interrupt()

Status
Not open for further replies.

almoes

Programmer
Jan 8, 2003
291
US
Now I run into another dilemma...Which is the best way to stop a thread. In Java Sun they say not to use stop(), in fact if I try to use it, it firsts forever, meaning that the next instances of the thread don't even run! Is interrupt the best way? If yes, will it continue were it was or start again? thanxs.

Cheers,
Alej
 
Thanxs! But if I create a complete new instance of the thread shouldn't it start again?

cheers,
alej
 
myRunnable myRunnableObj = new myRunnable();
Thread myThread = new Thread(myRunnableObj);
myThread.start();
...
myThread.interrupt();
myRunnableObj = null; // assign it to null if you do not use it anymore
myThread = null;

myRunnable myRunnableObj2 = new myRunnable();
Thread myThread2 = new Thread(myRunnableObj2);
myThread2.start();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top