I was reading an interview with Josh Bloch about the 2nd edition of his great book Effective Java on Java.net yesterday and was pleasantly surprised to find out that if you use volatile within the Double Check pattern it is now safe in JDK 5 and above.  I did not know this, the rumor mill was that Double Check did not work even in JDK 5.  Here’s an example of Double Check.  Josh suggests that you copy it as is and make no modifications.

// Double-check idiom for lazy initialization of instance fields.
private volatile FieldType field;
FieldType getField() {
    FieldType result = field;
    if (result == null) { // First check (no locking)
        synchronized(this) {
            result = field;
            if (result == null) // Second check (with locking)
                field = result = computeFieldValue();
     return result;

Just this revelation alone makes me want to buy his book.  I wonder what other goodies are in there.  Seriously though, I’ve had need for the double-check pattern a lot over the years as avoiding synchronization can be the biggest scalability  increase in writing middleware.  I’m psyched that it actually works!