Although the singleton pattern is now know as an anti-pattern, I think it still is a valid choice when you only need one instance in a particular context. Anyway, in Java there are several ways to implement a singleton.
For example this one uses a synchronized block:private Singleton singleton = null;
protected Singleton createSingleton() {
synchronized (this) { // locking on 'this' for
↧