Regarding static holder singleton pattern

This pattern is beneficial for at least 3 reasons:

  1. Static factory
  2. Lazy initialization
  3. Thread safe

The JVM defers initializing the InstanceHolder class until it is actually used, and because the Singleton is initialized with a static initializer, no additional synchronization is needed. The first call to getInstance by any thread causes InstanceHolder to be loaded and initialized, at which time the initialization of the Singleton happens through the static initializer.

Static holder pattern is also considered as the smartest replace for Double-check-locking antipattern.

Leave a Comment