ITPub博客

首页 > 应用开发 > > Thread.sleep() 的疑问

Thread.sleep() 的疑问

作者:pswyjz 时间:2019-09-06 09:36:41 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/755/viewspace-3120252/ ,如需转载,请注明出处,否则将追究法律责任。

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

注册时间:2019-11-21

  • 博文量
    213
  • 访问量
    28330