Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Created December 21, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/65ca9e93b95639c2548a771d559eb607 to your computer and use it in GitHub Desktop.
Save chathurangat/65ca9e93b95639c2548a771d559eb607 to your computer and use it in GitHub Desktop.
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