浅学设计模式--单例模式
来源:互联网 发布:淘宝官方amp服务商 编辑:程序博客网 时间:2024/06/15 15:14
单例模式很简单就不多介绍了,直接提供代码
1.线程不安全
public class Singleton{
private staitc Singleton singleton = null;
private Singleton(){
}
public Singleton getInstance(){
if(this.singleton == null){
return new Singleton();
}else{
return singleton ;
}
}
}
2.线程安全
public class Singleton{
private static final Singleton singleton = new Singleton();
private Singleton{
}
public synchronized static Singleton getInstance(){
return singleton ;
}
}
0 0
- 浅学设计模式--单例模式
- 浅学设计模式之单例<singleton>模式
- 浅学设计模式之单例<singleton>模式 .
- 浅学设计模式--代理模式
- 浅学设计模式之命令<command>模式
- 浅学设计模式之适配器<Adapter>模式
- 浅学设计模式之外观<Facade>模式
- 浅学设计模式之迭代器<Iterator>模式
- 浅学设计模式之状态<state>模式
- 浅学设计模式之状态<state>模式
- 浅学设计模式之迭代器<Iterator>模式
- 浅学设计模式之外观<Facade>模式
- 浅学设计模式之适配器<Adapter>模式 .
- 浅学设计模式之命令<command>模式
- 浅学设计模式之迭代器<Iterator>模式
- 浅学设计模式--策略(Strategy)模式
- 浅学Java设计模式之工厂模式
- 设计模式------单例模式
- tableview小结
- window平台下 Eclipse Ndk开发中的Method 'NewStringUTF' could not be resolved问题
- c语言socket通信
- java.util.prefs.WindowsPreferences <init>异常警告
- 简单几步在eclipse集成环境中代码显示行号
- 浅学设计模式--单例模式
- jni/../../Classes/AppDelegate.cpp:29: error: undefined reference to
- OpenCV 3.0.0 alpha compile by gcc cmake
- Node.js操作mongodb数据库
- The method getTextContent() is undefined for the type Node
- 每天一个linux命令(1):ifconfig命令
- Linux网络代码导读
- 委托多播
- 30个最佳免费的CSS HTML登录表单模板