Last active
December 20, 2017 19:27
-
-
Save chathurangat/fe8c34dba9c0ff828e2ec96f289d839b 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"); | |
synchronized (threadA) | |
{ | |
try { | |
System.out.println("Main thread is waiting for ThreadA "); | |
threadA.wait(); | |
System.out.println("Main thread resumed again"); | |
} catch (InterruptedException e) { | |
System.out.println("waiting thread interrupted "); | |
} | |
} | |
System.out.println("Main thread completed "); | |
} | |
} | |
class ThreadA extends Thread | |
{ | |
public void run() | |
{ | |
synchronized (this) { | |
System.out.println("ThreadA is running"); | |
notify(); | |
System.out.println("ThreadA called notify() on its own"); | |
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 synchronization block completed"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment