Skip to content

Instantly share code, notes, and snippets.

@doubledouble
Created May 15, 2012 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doubledouble/2699644 to your computer and use it in GitHub Desktop.
Save doubledouble/2699644 to your computer and use it in GitHub Desktop.
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