Running multiple Threads one after other
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sujit_komma
Posted On:   Monday, February 6, 2006 02:50 PM

I have five threads In first thread other four other threads have to run sequentially.

Line 1:public class Thread1 extends Thread{

Line 2: Thread2.start();

Line 3:if(Thread2.start())//if Thread2 has successfully run than
Line 4: Thread3.start();
Line 5:else{
exit
}
if(Thread3.start())
Thread4.start();
..

.
}

Any feedbacks is appreciated.

Thanks,

Sujit

Re: Running multiple Threads one after other

Posted By:   Jani_Kaarela  
Posted On:   Tuesday, February 7, 2006 03:57 AM


Use Thread.join() to wait for a thread to finish, then start the next one.


...
thread2.start();
thread2.join();
thread3.start();
thread3.join();
...

But why would you want to do this? Why not run the stuff sequentially in one thread and avoid the overhead of creating/managing multiple threads?!

About | Sitemap | Contact