BAEL-6139: Added ThreadMonitorInfo (#15094)

* BAEL-6139: Added ThreadMonitorInfo

* BAEL-6139: Move ThreadMonitorInfo

* BAEL-6139: Unsafe using park() and unpark(Thread)
This commit is contained in:
Eugene Kovko
2023-11-07 04:50:48 +01:00
committed by GitHub
parent 9e995c1e41
commit 14070ec048
5 changed files with 203 additions and 0 deletions
@@ -0,0 +1,26 @@
package com.baeldung.park;
import java.util.concurrent.locks.LockSupport;
public class ThreadMonitorInfo {
private static final Object MONITOR = new Object();
public static void main(String[] args) throws InterruptedException {
final Thread waitingThread = new Thread(() -> {
try {
synchronized (MONITOR) {
MONITOR.wait();
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}, "Waiting Thread");
final Thread parkedThread = new Thread(LockSupport::park, "Parked Thread");
waitingThread.start();
parkedThread.start();
waitingThread.join();
parkedThread.join();
}
}