ITPub博客

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

Thread.sleep() 的疑问

作者:cjk 时间:2019-08-21 10:29:26 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/4715/viewspace-3170015/ ,如需转载,请注明出处,否则将追究法律责任。

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

注册时间:2019-04-29

  • 博文量
    181
  • 访问量
    1133