Thread.sleep() 和Thread.currentThread().sleep()的区别

来源:互联网 发布:统计年鉴数据怎么下载 编辑:程序博客网 时间:2024/04/28 22:26

转:http://blog.csdn.net/sam031503/article/details/7076368

线程可以用继承Thread类或者实现Runnable接口来实现。

Thread.sleep()是Thread类的方法,只对当前线程起作用,睡眠一段时间。

如果线程是通过实现Runnable接口来实现的,则不是Thread类,不能直接使用Thread.sleep(),

必须使用Thread.currentThread()来得到当前线程的引用才可以调用sleep(),

所以要用Thread.currentThread().sleep()来睡眠。

 


ps:别人的理解经验分享,解释到位。不知道是否完全正确,谁能提一下意见?

0 0
原创粉丝点击