Example of incorrect double checked locking:
class Foo {
private Helper helper = null;
public Helper getHelper() {
if (helper == null)
synchronized(this) {
if (helper == null) helper = new Helper();
}
return helper;
}
}
// other functions and members...
}
Use the checkbox below to ignore double-checked locking on volatile fields. Using a volatile field for double-checked locking works correctly on JDK 1.5 and newer.