Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using the synchronized keyword on the method
class Singleton {
private static Singleton instance = null;
private Singleton(){}
public synchronized static Singleton getInstance(){
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