Do spurious wakeups in Java actually happen?

Seeing various locking related question and (almost) always finding the 'loop because of spurious wakeups' terms1 I wonder, has anyone experienced such kind of a wakeup (assuming a decent hardware/software environment for example)? I know the term 'spurious' means no apparent reason but what can be the reasons for such kind of an event? (1 Note: I'm not questioning the looping practice.) **Edit:** A helper question (for those who like code samples): If I have the following program, and I run it: public class Spurious { public static void main(String[] args) { Lock lock = new ReentrantLock(); Condition cond = lock.newCondition(); lock.lock(); try { try { cond.await(); System.out.println("Spurious wakeup!"); } catch (InterruptedException ex) { System.out.println("Just a regular interrupt."); } } finally { lock.unlock(); } } } What can I do to wake this `await` up spuriously without waiting forever for a random event?
For JVMs that run on POSIX systems and use pthread_cond_wait() the real question is "Why does pthread_cond_wait have spurious wakeups?".

以上就是Do spurious wakeups in Java actually happen?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准