ITPub博客

首页 > > > Thread.sleep() 的疑问

Thread.sleep() 的疑问

作者:mex 时间:2019-08-28 14:16:48 0 删除 编辑
class Run implements Runnable{
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " begin...");
Thread.sleep(1000*20);
System.out.println(Thread.currentThread().getName() + " over...");
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
public class TestThread {
public static void main(String[] args) {
Run run = new Run();
new Thread(run).start();
new Thread(run).start();
}
}
请问这段代码中 Thread.sleep(1000*20); //线程握住的锁是谁? 是run这个对象?还是谁?


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3932/viewspace-3154529/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-09

  • 博文量
    193
  • 访问量
    1886