Double checked locking technique for Java_127926469 - Gumtree/gumtree GitHub Wiki
Created by Tony Lam, last modified on Aug 17, 2009
This technique is used to avoid unnecessary object creation in the multi-threading environment when lazy instantiation is used.
References:
// Works with acquire/release semantics for volatile
// Broken under Java 1.4 and earlier semantics for volatile
class Foo {
private volatile Helper helper = null;
public Helper getHelper() {
if (helper == null) {
synchronized(this) {
if (null == helper)
helper = new Helper();
}
}
return helper;
}
}
- The "Double-Checked Locking is Broken" Declaration - Must read
- Double-checked locking - Wikipedia entry on this technique
Document generated by Confluence on Apr 01, 2015 00:11