码迷,mamicode.com
首页 > 编程语言 > 详细

Java-LockSupport的小例子

时间:2015-05-31 23:18:46      阅读:203      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!