Singleton-Pattern in Java
Das Singleton-Pattern in Java läßt sich eigentlich einfach implementieren… einfach falsch! In diesem Artikel ist eine Übersicht über alle Möglichkeiten gegeben und ich persönlich favorisiere die Bill pugh solution:
public class BillPughSingleton {
private BillPughSingleton() {}
private static class LazyHolder {
private static final BillPughSingleton INSTANCE = new BillPughSingleton();
}
public static BillPughSingleton getInstance() {
return LazyHolder.INSTANCE;
}
}