-
Notifications
You must be signed in to change notification settings - Fork 5
Double checked locking technique for Java_127926469
nxi edited this page Apr 9, 2015
·
1 revision
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
Home | Developer Guide | Copyright © 2013 ANSTO