Java-LockSupport的小例子

内容:结合一篇博文和自己写的简单例子学习,当然还可以看文档

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());
	}
}


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。