首页 > 编程语言 > 详细

Java-LockSupport的小例子

时间:2015-05-31 23:16:33      阅读:308      评论:0      收藏:0      [点我收藏+]

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

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


Java-LockSupport的小例子

原文:http://blog.csdn.net/u011345136/article/details/46293389

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!