• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

stopping the thread

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I am trying to stop a thread by using the method thread.stop(). but it is not stopping and I am getting exceptions when i am trying to run the prog. again.please suggest the solution ASAP.thank u
------------------
Arun
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the method stop has been deprecate dfor a couple of years now
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saiarun,
Yes, as Fred said Thread.stop() has been deprecated... Instead try and set your Thread object to null...
<code>
Thread t1 = new Thread();
t1.start();
Thread.sleep( 10000 );
t1 = null;
</code>
HTH,
-Nate
 
saiarun matcha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried. thanks for u r response.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Thread.stop() is depricated, Sun recommends that you control your thread's execution using a boolean variable. For example:
<PRE>
...
boolean running = false;
Thread runner;
...
public void run(){
running = true;
while(running){
// do cool stuff in here
// when some condition is met, set running to false
running = false;
// on the next loop the thread will exit its run method
}
}
...
</PRE>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!