Singleton Pattern
来源:互联网 发布:zepto.js与jquery区别 编辑:程序博客网 时间:2024/04/29 03:21
Singleton Pattern:
1. Early mode
public class President{ private static President instance = new President(); private President() {} public static President getInstance() { return instance; }}
2. Lazy mode:
public class President{ private static President instance; private President() {} public static synchronized President getInstance() { if(instace == null){ instance = new President(); } return instance; }}
3. Optimize solution: (double checked locking)
public class President{ private static volatile President instance; private President() {} public static President getInstance() { if(instance == null) { synchronized(President.class){ if(instance == null){ instance = new President(); } } } return instance; }}
0 0
- singleton pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton pattern
- Singleton Pattern
- Singleton Pattern
- singleton pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton Pattern
- Singleton pattern
- codeforces 701C They Are Everywhere(尺取法)
- 利用无线网卡建立个人wifi hotspot
- POJ1328-Radar Installation
- 关于在MySQL中实现upsert操作
- Generate Parentheses
- Singleton Pattern
- 基于SQL语句的断码查询
- 从零开始学习设计模式——简单工厂模式
- ST表的应用(poj--3368)
- Factory Pattern
- GAME TIMERS: ISSUES AND SOLUTIONS.
- Swing线程之SwingUtilities.invokeLater解释
- Swap Nodes in Pairs
- Swing之JList的使用