Last active
November 28, 2016 08:48
-
-
Save elvismetaphor/dbe7793a079b5c9c568126ad5ecee002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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