Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Singleton
/**
* see http://caterpillar.onlyfun.net/Gossip/DesignPattern/SingletonPattern.htm
* http://www.jackforfun.com/2007/07/java-synchronized.html
*/
public class Singleton {
private static Singleton instance = null;
private Singleton(){}
public static Singleton getInstance() {
if (instance == null){
synchronized(Singleton.class){
if(instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.