Skip to content

Instantly share code, notes, and snippets.

@dreampiggy
Created June 14, 2016 13:48
Show Gist options
  • Save dreampiggy/7713be924951cbb6d89a062d3e40ff02 to your computer and use it in GitHub Desktop.
Save dreampiggy/7713be924951cbb6d89a062d3e40ff02 to your computer and use it in GitHub Desktop.
Java Singleton
public class Singleton {
private volatile static Singleton singleton;
private Singleton (){}
public static Singleton getSingleton() {
if (singleton == null) {
synchronized (Singleton.class) {
if (singleton == null) {
singleton = new Singleton();
}
}
}
return singleton;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment