Skip to content

Instantly share code, notes, and snippets.

@anjanashankar9
Last active November 22, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anjanashankar9/a36e39b33a19b0ee5d00a520bb3ce360 to your computer and use it in GitHub Desktop.
Save anjanashankar9/a36e39b33a19b0ee5d00a520bb3ce360 to your computer and use it in GitHub Desktop.
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