• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stopping a Thread

 
sridhar lakka
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Thanks a lot in advance.
As stop() method is depricate we should not use stop() method to stop a thread.
But without using stop() method how can we stop a thread from execution.

Please tell me.
Regards,
Sree
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The general approach is to set a boolean variable ("doStop" or something like that) from outside the class. The code in the thread should then check that variable periodically, and quit if it finds it to be set.
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This old thread discusses the stop method and the solution proposed by Ulf.
 
Jim Cheng
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could try to use interrupt() to interrupt the thread,
which might thows some exceptions
 
shankar reddy
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim Cheng,
interrupt method was deprecated. He is asking about how to stop.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shankar reddy telukutla:
interrupt method was deprecated.

Boy!!! when did that happen???

Originally posted by shankar reddy telukutla:
He is asking about how to stop.


Interrupt is a way to co-operatively stop a thread.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[shankar reddy telukutla]: interrupt method was deprecated.

No, it wasn't. At all.

Note that the API does link to a nice discussion of the methods that actually are deprecated, and what to do instead.
[ October 10, 2007: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!