Skip to content

Instantly share code, notes, and snippets.

@elvismetaphor
Last active November 28, 2016 08:48
Show Gist options
  • Save elvismetaphor/dbe7793a079b5c9c568126ad5ecee002 to your computer and use it in GitHub Desktop.
Save elvismetaphor/dbe7793a079b5c9c568126ad5ecee002 to your computer and use it in GitHub Desktop.
public class SingletonSample{
private static SingletonSample instance= null;
private static Object mutex= new Object();
private String value;
private SingletonSample(){}
public static SingletonSample getInstance(){
if (instance == null) {
synchronized (mutex) {
if(instance == null) instance= new SingletonSample();
}
}
return instance;
}
public synchronized void setter(String value) {
this.value = value;
}
public synchronized String getter() {
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment