Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Synchronized block
class Singleton {
private static Singleton instance = null;
private Singleton(){}
public static Singleton getInstance(){
if (instance == null) {
synchronized {
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