• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

why using double sync check on map

 
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

 
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.
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic