Created
January 16, 2015 12:43
-
-
Save sqtds/86c12920c723c08329ba to your computer and use it in GitHub Desktop.
单例延迟加载
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
| /** | |
| * <p>类说明:</p> | |
| * | |
| * @version 1.0 | |
| * <p>文件名:Singlen</p> | |
| * <p>创建人及时间: suntiancheng 2015/1/16</p> | |
| * <p/> | |
| * <p>修改人:</p> | |
| * <p>修改时间:</p> | |
| * <p>修改描述:</p> | |
| */ | |
| public class Singleton { | |
| /** | |
| * 类级的内部类,也就是静态的成员式内部类,该内部类的实例与外部类的实例 | |
| * 没有绑定关系,而且只有被调用到时才会装载,从而实现了延迟加载 | |
| */ | |
| private static class SingletonHolder { | |
| /** | |
| * 静态初始化器,由JVM来保证线程安全 | |
| */ | |
| private static Singleton instance = new Singleton(); | |
| } | |
| /** | |
| * 私有化构造方法 | |
| */ | |
| private Singleton() { | |
| } | |
| public static Singleton getInstance() { | |
| return SingletonHolder.instance; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment