In the article "Implementing a Data Cache using Readers and Writers" the author uses, in the paragraph "Creating a lock" the "Double-Checked Locking" idiom to avoid a synchronized method. As I understand it this does not work. More information is available from http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html which has a detailed explanation of why this is. I wonder if anyone has any comments about this.
- Posted by: Alex Moffat
- Posted on: April 10 2001 09:13 EDT
- "Implementing a ... and Writers" uses broken idiom by Costin Cozianu on April 10 2001 17:36 EDT
We need to hold Billy gravely responsible for this terrible mistake :)
There are two errors there:
- Static singletons with lazy instantiation can safely be implemented without double checked locking by using a separate class with static initializer.
- lazy instantiation is really unnecessary for that particular case.
Billy, what's up man ?