当前位置:网站首页>The difference between the lazy mode of singleton mode and the evil mode
The difference between the lazy mode of singleton mode and the evil mode
2022-07-01 16:47:00 【Fried tomatoes with duck eggs】
The lazy type is , Only when using this use case , Then instantiate it , So be more efficient .
public class SingletonLH {
private static SingletonLH instance;
private SingletonLH(){};
public static SingletonLH getInstance(){
if (instance==null){
instance=new SingletonLH();
}
return instance;
}
public static void main(String[] args) {
SingletonLH instance = SingletonLH.getInstance();
System.out.println(instance);
}
}
Hungry Han style is the program as soon as it starts , Just instantiate him , When he is used, the time of re instance is saved , So the speed and response are fast . This is the difference between the two
public class SingletonEH {
private static SingletonEH instance =new SingletonEH();
private SingletonEH(){};
public static SingletonEH getInstance(){
System.out.println("instance:"+instance);
System.out.println(" Load hungry Chinese style ");
return instance;
}
public static void main(String[] args) {
SingletonEH instance = SingletonEH.getInstance();
System.out.println(instance);
}
}
The two biggest differences are that one is instantiation at the beginning , One is to wait until it is used
边栏推荐
- Rhcsa Road
- What is the digital transformation of manufacturing industry
- Is the securities account given by the head teacher of goucai school safe? Can I open an account?
- 数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
- Go language source level debugger delve
- 如何使用phpIPAM来管理IP地址和子网
- 【PyG】文档总结以及项目经验(持续更新
- Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
- Rhcsa Road
- [daily question] 1175 Prime permutation
猜你喜欢

VMware 虛擬機啟動時出現故障:VMware Workstation 與 Hyper-v 不兼容...

【Hot100】19. Delete the penultimate node of the linked list

阿里云、追一科技抢滩对话式AI

【观察】数字化时代的咨询往何处走?软通咨询的思与行

Ring iron pronunciation, dynamic and noiseless, strong and brilliant, magic wave hifiair Bluetooth headset evaluation

今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!

【Hot100】20. Valid parentheses

How to repair the laptop that cannot connect to the wireless network

Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist

PR basic clip operation / video export operation
随机推荐
Go language source level debugger delve
Detailed explanation of activity life cycle and startup mode
C語言輸入/輸出流和文件操作
Red team Chapter 8: blind guess the difficult utilization process of the package to upload vulnerabilities
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
Redis 分布式锁
数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
Sweden announced its decision to exclude Huawei 5g equipment, but Huawei has successfully found a new way out
制造业数字化转型究竟是什么
SystemVerilog-结构体(二)
[flask introduction series] cookies and session
Hi Fun Summer, play SQL planner with starrocks!
Preliminary study on golang crawler framework
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
单例模式的懒汉模式跟恶汉模式的区别
Principle of SSM framework
Stonedb is building blocks for domestic databases, and the integrated real-time HTAP database based on MySQL is officially open source!
Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI