Hi, All,
I'm thinking out loud here, and hopefully no one is offended by my comments.
I'm studying for the OCP with the Boyarsky/Selikoff book, and overall I find it and excellent resource. I'm also reading other books in parallel. In Chapter 2 of Boyarsky/Selikoff they are talking about the Singleton
pattern, and on p81 in a "Real World Scenario" they mention the double ckecked locking mechanism for lazy initialization (and do use the volatile keyword). The book specifically states that "The solution is to use double-checked locking, a design pattern ......". However,
Java Concurrency in Practice (another great resource) states that double checked locking is an outdated pattern for lazy initialization (even if it would work properly with the volatile keyword), and that a better mechanism for lazy initialization would be the "lazy initialization holder class idiom". In fact, JCP actually lists double ckecked locking as one of the "bugs" that FindBugs looks for when analyzing code for bug patterns.
So, any thoughts? I understand that this topic is beyond the scope of the exam, but I'm just curious what the experts think about this. Why talk about double checked locking when there is a better pattern out there? Or maybe it's not better and JCP is wrong?
Thanks