Skip to content

Instantly share code, notes, and snippets.

@kyze8439690
Created November 4, 2013 12:53
Show Gist options
  • Save kyze8439690/7302016 to your computer and use it in GitHub Desktop.
Save kyze8439690/7302016 to your computer and use it in GitHub Desktop.
singleton pattern
public class Singleton {
private static Object obj = new Object();
private static Singleton instance = null;
private Singleton(){
}
public static Singleton getInstance() {
// if already inited, no need to get lock everytime
if (instance == null) {
synchronized (obj) {
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