This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes To stop a thread which is running?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "To stop a thread which is running??" Watch "To stop a thread which is running??" New topic
Author

To stop a thread which is running??

andral
Greenhorn

Joined: Oct 09, 2007
Posts: 6
How to stop a thread which is already running? with out using stop method, as this method is already deprecated.
[ February 27, 2008: Message edited by: andral ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35241
    
    7
Hello "andral"-

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, the usual solution is to set a boolean value somewhere, which would then be checked periodically from the running thread. In other words, the thread needs to be implemented in such a way that it can terminate itself if asked to do so.


Android appsImageJ pluginsJava web charts
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16690
    
  19

Originally posted by andral:
How to stop a thread which is already running? with out using stop method, as this method is already deprecated.


Without using the stop() method, your threads need to behave in a cooperative manner. It means that your thread needs to check a flag, once in a while, and stop (via returning from the run() method), when it is asked to do so.

Henry
[ March 01, 2008: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To stop a thread which is running??
 
Similar Threads
help me..............
Question on join() method for Bert
About Thread question?
Q on thread at Jxam
code for thread exceution?