Skip to content

Instantly share code, notes, and snippets.

@cortix
Created October 6, 2021 12:07
Show Gist options
  • Save cortix/b61372cf1a27fb8339f894990bdef26f to your computer and use it in GitHub Desktop.
Save cortix/b61372cf1a27fb8339f894990bdef26f to your computer and use it in GitHub Desktop.
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