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
}
}

1 comment:

精采表演 said...

keep sharing with us, please....I will waiting your up date everyday!! Have a nice and relax day!........................................