内容:结合一篇博文和自己写的简单例子学习,当然还可以看文档
public class TestLockSupport {
public static class MyRunnable implements Runnable {
private final Thread currentThread;
public MyRunnable(Thread thread) {
this.currentThread = thread;
}
@Override
public void run() {
try {
Thread.sleep(5000);
LockSupport.unpark(this.currentThread);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Thread thread = new Thread(new MyRunnable(Thread.currentThread()));
thread.start();
System.out.println(new Date());
LockSupport.park();
System.out.println(new Date());
}
}