Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.