...
Code Block | ||||
---|---|---|---|---|
| ||||
public final class Helper { private final int n; public Helper(int n) { this.n = n; } // Other fields and methods, all fields are final } final class Foo { private Helper helper = null; public Helper getHelper() { private Helper h = helper; // only one racy read of helper if (h == null) { synchronized (this) { h = helper; if (h == null) { h = new Helper(42); helper = h; } } } return h; } } |
...