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()); } }
时间: 2024-10-11 17:30:14