Home arrow static arrow Java Programming [Archive] - Making a Thread that can stop itself
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Making a Thread that can stop itself
This topic has 6 replies on 1 page.

Posts:297
Registered: 4/10/04
Making a Thread that can stop itself  
Jun 21, 2004 4:42 PM



 
I made a Thread this way;

new Thread(new Runnable(){
public void run(){

}
}).start();

how can I get this Thread to stop itself???
 

Posts:1,183
Registered: 1/23/02
Re: Making a Thread that can stop itself  
Jun 21, 2004 4:47 PM (reply 1 of 6)



 
Fall out of run().
 

Posts:297
Registered: 4/10/04
Re: Making a Thread that can stop itself  
Jun 22, 2004 6:43 AM (reply 2 of 6)



 
Do you mean, return?
 

Posts:447
Registered: 3/8/01
Re: Making a Thread that can stop itself  
Jun 22, 2004 6:45 AM (reply 3 of 6)



 
Yes. Whenever run() finishes, the thread ends. There is no other fully safe way to end a thread.
 

Posts:957
Registered: 3/31/04
Re: Making a Thread that can stop itself  
Jun 22, 2004 7:33 AM (reply 4 of 6)



 
I usually put an internal counter inside.

while(threadLife > 0){    threadLife--; }


Is that what you meant?
 

Posts:417
Registered: 5/15/03
Re: Making a Thread that can stop itself  
Jun 22, 2004 7:39 AM (reply 5 of 6)



 
What happens when an unstoppable thread hits an unmoveable block of code?
 

Posts:1,183
Registered: 1/23/02
Re: Making a Thread that can stop itself  
Jun 22, 2004 7:59 AM (reply 6 of 6)



 
What happens when an unstoppable thread hits an unmoveable block of code?

I'd like to see that tested experementally at CERN :-)
 
This topic has 6 replies on 1 page.