单例模式
来源:互联网 发布:stc89c51单片机烧录 编辑:程序博客网 时间:2024/06/05 21:51
/** * 懒汉式 */public class Singleton { private static Singleton instance; /** * 1.构造方法私有化 */ private Singleton(){ System.out.println("创建对象"); } /** * 根据对象是否为空进行创建 */ public static synchronized Singleton getInstance(){ if(instance==null){ instance = new Singleton(); } return instance; }}
/** * 饿汉式 */public class Singleton { private static Singleton instance = new Singleton(); /** * 1.构造方法私有化 */ private Singleton(){ System.out.println("创建对象"); } public static Singleton getInstance(){ return instance; }}
0 0
- 单例、单例模式
- 单例模式-多线程单例模式
- 单件模式(单例模式)
- 设计模式------单例模式
- 设计模式------单例模式
- 设计模式-单例模式
- 设计模式 - 单例模式
- 设计模式---单例模式
- 设计模式---单例模式
- PHP模式-单例模式
- 【设计模式】单例模式
- 设计模式-单例模式
- 设计模式----单例模式
- 设计模式--单例模式
- 设计模式-单例模式
- 单例模式(单子模式)
- 设计模式-单例模式
- [设计模式] 单例模式
- swustoj字符串查找(0448)
- 图片预加载的几个注意点
- Linux相关命令记录
- ERP安全
- MySQL数据类型
- 单例模式
- spring boot-使用redis的Keyspace Notifications实现定时任务队列
- 24 点游戏
- Linux errno值含义 与 思考(致命与可修正错误类型)
- spring json
- Iterator
- HDU 2795 Billboard (线段树)
- git
- 待查看网址备份