Thursday, December 24, 2009

Singleton Pattern with Lazy Initialization On Demand Holder

This is one of the better ways to implementing a singleton class (class which lets user create one and only one instance).

It uses Initialization on demand holder pattern.



public class Singleton {
private static class LazyHolder {
private static final Singleton instance = new Singleton();
}

public static Singleton getInstance() {
return LazyHolder.instance;
}

private Singleton() {
//initialize singleton instance
}
}

No comments:

Book notes: Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems, by Martin Kleppmann

My notes from the excellent book on how software has evolved to handle data from hierarchical databases to the NoSQL -  https://www.goodrea...