spurious-wakeup

Unexpected thread wakeup

*爱你&永不变心* 提交于 2019-12-10 17:34:27
问题 I was expecting the second thread in the following example to hang, since it waits on an object with no corresponding notify. Instead, it falls through to the println, presumably due to a spurious wakeup. public class Spurious { public static void main(String[] args) { Thread t1 = new Thread() { public void run() { System.out.println("Hey!"); } }; Thread t2 = new Thread() { public void run() { try { synchronized (t1) { t1.wait(); } } catch (InterruptedException e) { return; } System.out

Do spurious wakeups in Java actually happen?

三世轮回 提交于 2019-11-26 01:46:27
问题 Seeing various locking related question and (almost) always finding the \'loop because of spurious wakeups\' terms 1 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

Do spurious wakeups in Java actually happen?

旧时模样 提交于 2019-11-25 23:33:50
Seeing various locking related question and (almost) always finding the 'loop because of spurious wakeups' terms 1 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();