• Post Reply Bookmark Topic Watch Topic
  • New Topic

why using double sync check on map  RSS feed

 
jv patel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
in the code, why using double sync check on map instead of using enum for singleton design pattern

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jv patel wrote:Hello everyone,
in the code, why using double sync check on map instead of using enum for singleton design pattern


I assume you mean "Double-checked locking". There is no reason to ever use DCL in Java. In fact, before 1.3 or 1.4, the memory model allowed that idiom to fail. I can work in later versions, but there's still no reason to ever use it. I may give very, very small performance gains in lazily instantiated singletons, but there's no reason to lazily instantiate a singleton anyway.

Just forget DCL exists entirely. It's broken and useless.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!