It is worth noting that broken techniques like double-checked locking are still broken under the new memory model, and that "fixing" double-checked locking was not one of the goals of the new memory model effort. (However, the new semantics of volatile allow one of the commonly proposed alternatives to double-checked locking to work correctly, although the technique is still discouraged.)
Related discussions:
- Why Double checked locking is 25% faster in Joshua Bloch Effective Java Example
- Why is double-checked locking broken in Java?
I can understand why it is broken without the volatile
fix. but I don't know why it is still discouraged even after the fix. I noticed some disagreement in one of the discussions. but if it is really as the reference suggested ? what could be the reason this fixed version is still discouraged?