Created
August 5, 2014 03:25
-
-
Save zhangyangjing/4635ae640525a570608b to your computer and use it in GitHub Desktop.
SingletonSample
This file contains hidden or 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 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