我有一个功能:
Thread myThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(500);
myThread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});调用Thread.sleep(500);与调用myThread.sleep(500);相同
这两个不同的电话之间有什么不同吗?
发布于 2013-09-19 18:38:50
公共静态空睡眠(Long millis)抛出InterruptedException 使当前执行的线程在指定的毫秒内休眠(暂时停止执行),这取决于系统定时器和调度器的精度和准确性。线程不会失去任何监视器的所有权。
睡眠()方法是静态的。它应该始终被称为Thread.sleep()。写入otherThread.sleep()不会导致otherThread休眠;它会导致当前线程休眠。
https://stackoverflow.com/questions/18902461
复制相似问题