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.
Activity
bhaskar253 commentedon Jul 18, 2020
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.
Miha-x64 commentedon Jul 18, 2020
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.
roeniss commentedon Apr 27, 2021
@Miha-x64 what spec do you reference exactly?
Miha-x64 commentedon Apr 27, 2021
@roeniss https://docs.oracle.com/javase/specs/jls/se16/html/jls-12.html#jls-12.4.1