Skip to content

Instantly share code, notes, and snippets.

@zhangyangjing
Created August 5, 2014 03:25
Show Gist options
  • Save zhangyangjing/4635ae640525a570608b to your computer and use it in GitHub Desktop.
Save zhangyangjing/4635ae640525a570608b to your computer and use it in GitHub Desktop.
SingletonSample
public class SingletonSample {
private static SingletonSample mInstance;
private SingletonSample() {
}
public static SingletonSample getInstance() {
if (null == mInstance) {
synchronized(SingletonSample.class) {
if (null == mInstance) {
mInstance = new SingletonSample();
}
}
}
return mInstance;
}
public static void main(String[] args) {
String str = SingletonSample.getInstance().toString();
System.out.println(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment