BJ *_*ruz 6 java concurrency multithreading busy-loop
为什么写下面的代码被认为是不好的做法有什么原因?
while (someList.isEmpty()) {
try {
Thread.currentThread().sleep(100);
}
catch (Exception e) {}
}
// Do something to the list as soon as some thread adds an element to it.
Run Code Online (Sandbox Code Playgroud)
对我来说,选择一个任意值进行睡眠并不是一种好的做法,我会BlockingQueue在这种情况下使用a ,但我想知道为什么不应该写这样的代码有多个原因.