Created
December 22, 2016 06:09
-
-
Save Orange168/b764b1d3080050d271d93d083931cc10 to your computer and use it in GitHub Desktop.
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 INSTANCE; //声明成 volatile | |
private Singleton (){} | |
public static Singleton getSingleton() { | |
if (INSTANCE == null) { | |
synchronized (Singleton.class) { | |
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