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 ]
Joined: Mar 22, 2005
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.
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 ]