Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Advanced
Aug 24, 2004



Application Security Testing: An Integral Part of DevOps

Use join() to Check if a Thread Has Finished

Suppose you start a thread and you want to wait for that thread to finish before you continue processing. One way is to keep checking if the thread has finished by using the isAlive() method of your thread. However, this keeps the processor busy with repetitive check of the status of the thread.

A more efficient way to do this is to use the join() method of your thread as follows:

MyThread myThread = new MyThread();
catch(InterruptedException ie)
System.out.println("I'm done");
This way, the main thread is joined to myThread and waits for myThread to die. As soon as myThread dies, "I'm Done" is printed, denoting that the main thread was waiting until now.
Amit Tuli
Comment and Contribute






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



Thanks for your registration, follow us on our social networks to keep up-to-date