首页 > 应用开发 > > Thread.sleep() 的疑问
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/ ,如需转载,请注明出处,否则将追究法律责任。