Home arrow static arrow Java Programming [Archive] - teach me thread programming
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - teach me thread programming
This topic has 5 replies on 1 page.

Posts:75
Registered: 4/22/04
teach me thread programming  
Aug 4, 2004 3:33 PM



 
How the following can be achieved?

//Thread t1 is running.

//Start Thread t2 from t1.

//Halt t1 for a few seconds while t2 runs.

//Wake t1, stop (destroy) t2

Would someone give the code snippet?

Thank you.
 

Posts:2,206
Registered: 8/15/02
Re: teach me thread programming  
Aug 4, 2004 3:34 PM (reply 1 of 5)



 
Not me, it's my lunchtime
 

Posts:37,103
Registered: 3/30/99
Re: teach me thread programming  
Aug 4, 2004 3:37 PM (reply 2 of 5)



 
http://java.sun.com/docs/books/tutorial/essential/threads/

Be aware, though, that stopping a thread at an arbitrary point is a bad idea. Rather you should set a flag that the thread periodically checks to determine whether it should continue processing.
 

Posts:329
Registered: 1/6/04
Re: teach me thread programming  
Aug 4, 2004 3:38 PM (reply 3 of 5)



 
How the following can be achieved?

//Thread t1 is running.

//Start Thread t2 from t1.

//Halt t1 for a few seconds while t2 runs.

//Wake t1, stop (destroy) t2

Would someone give the code snippet?

Thank you.

Sun has a tutorial on threads that might interest you:
http://java.sun.com/docs/books/tutorial/essential/threads/index.html
 

Posts:13,250
Registered: 24/10/97
Re: teach me thread programming  
Aug 4, 2004 3:39 PM (reply 4 of 5)



 
Not me, it's my lunchtime

Nor me! I'm about to go to bed.
 

Posts:2,909
Registered: 13.8.2003
Re: teach me thread programming  
Aug 4, 2004 11:31 PM (reply 5 of 5)



 
Thread t1 = new Thread("Thread-1").start();// in t1   Thread t2 = new Thread("Thread-2").start();   t2.join(1000);     // let t2 run for a second   // stop t2


Stopping the thread must be done in a safe way, such as setting a boolean variable to false in the run() method's loop (the standard way to stop a thread, search for it if you don't know it yet).
 
This topic has 5 replies on 1 page.