>>21
BEWARE
/prog/ THIS IS NOT THREAD SAFE, DO NOT INCLUDE THIS IN ANY ENTERPRISE APPLICATIONS.
Fixed:
public class EnterpriseSingleton {
private static EnterpriseSingleton enterpriseSingleton;
private EnterpriseSingleton() {
}
public static EnterpriseSingleton getInstance() {
if (enterpriseSingleton == null) {
synchronized (EnterpriseSingleton.class) {
if (enterpriseSingleton == null) {
enterpriseSingleton = new EnterpriseSingleton();
}
}
}
return enterpriseSingleton;
}
}
This version also alleviates the performance overhead associated with using synchronized blocks.