public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, InterruptedException {
Unsafe unsafe = UnsafeUtil.getUnsafe();
Thread currThread = Thread.currentThread();
new Thread(()->{
try {
Thread.sleep(3000);
currThread.interrupt();
//unsafe.unpark(currThread);
} catch (Exception e) {
System.out.println(e);
}
}).start();
unsafe.park(false, 0);
//currThread.sleep(5000);
System.out.println("SUCCESS!!!");
}
result: the program will not report an error and print success after three seconds
if you replace unsafe.park (false, 0); with currThread.sleep (5000), a thread interrupt exception will be reported.
I know that Thread.interrupt will throw an InterruptedException exception on a blocked thread.
but isn"t park blocking? In fact, I haven"t quite understood the difference between the Object.wait () and Unsafe.park () methods.
also ask the great gods to help explain.