Skip to content

Instantly share code, notes, and snippets.

@Orange168
Created December 22, 2016 06:09
Show Gist options
  • Save Orange168/b764b1d3080050d271d93d083931cc10 to your computer and use it in GitHub Desktop.
Save Orange168/b764b1d3080050d271d93d083931cc10 to your computer and use it in GitHub Desktop.
Singleton
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