You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
private static final Singleton instance = new Singleton();
is actually the eager initialization which will cause a slowdown in your application during startup.
The alternatives that can be used in place of the above mentioned double-check synchronized lock
is Bill-Pugh's Singleton & Enums, both of these are thread-safe and allows lazy initialization.
This is wrong because classes are loaded lazily, according to JVM spec.
Enums are genereted in exactly same way: public static constants are assigned during static initialization.
design-patterns-java/src/refactoring_guru/singleton/example/thread_safe/Singleton.java
Lines 43 to 52 in 7601425
Why do you prefer this overcomplicated code instead of concise, simple, thread-safe, and lazy enough
?
The text was updated successfully, but these errors were encountered: