I have 2 options:
Singleton Pattern
class Singleton{ private static Singleton singleton = null; public static synchronized Singleton getInstance(){ if(singleton == null){ singleton = new Singleton(); } return singleton; } }
using a
static final
fieldprivate static final Singleton singleton = new Singleton(); public static Singleton getSingleton() { return singleton; }
Whats the difference? (singlethreaded or multithreaded)
Updates: I am aware of Bill Pugh or enum
method.
I am not looking for the correct way, but I have only used 1. Is there really any difference b/w 1 or 2?