Skip to content

Instantly share code, notes, and snippets.

@anjanashankar9
Last active November 24, 2020 17:25
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/d5be8f0664680b09298531afcafd8574 to your computer and use it in GitHub Desktop.
Save anjanashankar9/d5be8f0664680b09298531afcafd8574 to your computer and use it in GitHub Desktop.
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