Is it better to use the double checked locking idiom for a singleton pattern? Or a synchronised method?
ie:
private static volatile ProcessManager singleton = null;
public static ProcessManager getInstance() throws Exception {
if (singleton == null) {
synchronized (MyClass.class) {
if (singleton == null) {
singleton = new ProcessManager();
}
}
}
return singleton;
}
or
private static processManager singleton = null;
public synchronized static processManager getInsatnce() throws Exception {
if(singleton == null) {
singleton = new processManager();
}
return singleton
}