Created
December 21, 2017 17:07
-
-
Save chathurangat/65ca9e93b95639c2548a771d559eb607 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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