How do I have one thread wait for another thread to finish before continuing?

John Zukowski

You can wait for a thread to finish by calling its join() method. For instance, in the following code, the current thread will wait until thread2 finishes before printing Done.

thread2.start();
// do more stuff here
thread2.join();
System.out.println("Done");
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact