Forcing a spurious-wake up in Java

Viewed 3777

This question is not about, whether spurious wakeups actually happen, because this was already discussed in full length here: Do spurious wakeups in Java actually happen? Therefore this is also not about, why I do have to put a loop around my wait Statement. What this is about:

I would like to construct a case, where the spurious wake-up happens. What I've learned so far in the question linked above is this:

If a Linux process is signaled its waiting threads will each enjoy a nice, hot spurious wakeup.

So it seems this will only work a linux machine, in fact I have Ubuntu 11.04 - 64-Bit. I have written a Java program with one thread waiting for a condition, but without loop and another class on which a thread just waits and get notified by another thread. I thought launching all three threads in one JVM would force the case described above, but it seems like this is not the case.

Has anyone else another idea how to construct such a case in Java?

7 Answers

The amount of spurious wake-ups is directly proportional to the amount of processor cores in your system.

On a system with 24+ cores, it should be easy to encounter spurious wakeups. (Some bloggers would go as far to claim that roughly 40% of their waits are interrupted on those systems. But there surely are other factors to consider in the equation, making it hard to put a number on it.).

Related