Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Application
{
public static void main(String[] args)
{
System.out.println("Main thread started ");
ThreadA threadA = new ThreadA();
threadA.start();
System.out.println("ThreadA was started");
try {
System.out.println("Main thread is waiting until ThreadA completes");
threadA.join();
System.out.println("Main thread resumed again after completing ThreadA");
} catch (InterruptedException e) {
System.out.println("waiting thread interrupted ");
}
System.out.println("Main thread completed ");
}
}
class ThreadA extends Thread
{
public void run()
{
System.out.println("ThreadA is running");
try {
System.out.println("ThreadA sleeps for 5 seconds");
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println("sleeping thread interrupted ");
}
System.out.println("ThreadA completed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment