Created
June 14, 2016 13:48
-
-
Save dreampiggy/7713be924951cbb6d89a062d3e40ff02 to your computer and use it in GitHub Desktop.
Java Singleton
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 Singleton { | |
private volatile static Singleton singleton; | |
private Singleton (){} | |
public static Singleton getSingleton() { | |
if (singleton == null) { | |
synchronized (Singleton.class) { | |
if (singleton == null) { | |
singleton = new Singleton(); | |
} | |
} | |
} | |
return singleton; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment