单例设计模式
来源:互联网 发布:浮雕制作软件 编辑:程序博客网 时间:2024/06/05 18:36
单例设计模式
标准单例
public class Singleton{ private static final Singleton singleton = new Singleton(); private Singleton(){ } public static Singleton getSingleton(){ return singleton; } //类中其他方法,尽量是static(因为getSingleton是static的) public static void doSomething(){ }}
饿汉模式单例
public class Singleton{ private static final Singleton singleton = new Singleton(); private Singleton(){ } public static Singleton getSingleton(){ return singleton; } public static void doSomething(){ }}
懒汉模式单例
public class Singleton{ private Singleton singleton = null; private Singleton(){} public static synchronized Singleton getSingleton(){ if(singleton == null){ singleton = new Singleton(); } return singleton; }}
阅读全文
0 0
- 设计模式--单例
- 单例设计模式
- 设计模式----单例
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 设计模式-单例
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- 单例设计模式
- windows 下jdk版本切换问题
- Android hellochart折线图各属性设置
- 学期总结
- Spring MVC中如何传递对象参数
- javascript中基础但是很容易忽略的点
- 单例设计模式
- markdown转换word,pandoc
- Win7下Laravel简单安装
- 在当前Activity中finish掉其它Activity的方法
- HDU 6249
- 第14周项目1(8)- 验证算法 基数排序
- [转]MFC运行机制(自认为介绍比较清晰的)
- 开源时序数据库influxDB解决方案
- springcloud实战之1 技术选型:dubbo还是springcloud