JavaMemoryModel: Code that sleeps and expects to see changes

From: Bill Pugh (
Date: Sun Oct 24 1999 - 13:26:08 EDT

As much as I would be happy to rule that programs that
sleep in a loop without synchronization and expect to see
changes are just wrong, I think this may be the
one area where the strongest reeducation campaign is

>From Sun's demo programs included with jdk1.3 beta:

Here is the code from demo/applet/Blink/

    Thread blinker = null; // The thread that displays images

    public void run() {
        Thread me = Thread.currentThread();
        while (blinker == me) {
            try {
            catch (InterruptedException e) {
    public void stop() {
        blinker = null;

The identical idiom appears in:

Very similar idioms (that would also fail) appear in:
JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:20 EDT