Created
October 6, 2021 12:07
-
-
Save cortix/b61372cf1a27fb8339f894990bdef26f 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 Main19 { | |
public static void main(String[] args) throws InterruptedException { | |
Object obj = new Object(); | |
Runnable r1 = () -> { | |
try { | |
synchronized (obj) { | |
obj.wait(); | |
} | |
} catch (InterruptedException ex) { | |
System.out.println("interrupted"); | |
} | |
}; | |
Runnable r2 = () -> { | |
synchronized (obj) { | |
obj.notifyAll(); | |
try { | |
Thread.sleep(10000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
}; | |
Thread t0 = new Thread(r1); | |
t0.start(); | |
Thread t1 = new Thread(r1); | |
t1.start(); | |
Thread t2 = new Thread(r1); | |
t2.start(); | |
Thread t3 = new Thread(r1); | |
t3.start(); | |
Thread t4 = new Thread(r2); | |
t4.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment