This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

To stop a thread which is running??  RSS feed

 
andral
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!