当前位置:网站首页>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
边栏推荐
- 毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
- Virtual serial port simulator and serial port debugging assistant tutorial "suggestions collection"
- Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
- SystemVerilog-结构体(二)
- Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
- Is the programmer's career really short?
- sql刷题584. 寻找用户推荐人
- Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
- 模板引擎Velocity 基礎
- Flux d'entrées / sorties et opérations de fichiers en langage C
猜你喜欢

Germany if was crowned with many awards. How strong is this pair of headphones? In depth evaluation of yinpo GTW 270 hybrid

Guide for high-end programmers to fish at work
![[nodemon] app crashed - waiting for file changes before starting...解决方法](/img/ee/9830afd86e092851a2a906cb994949.png)
[nodemon] app crashed - waiting for file changes before starting...解决方法
![[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment](/img/0e/52e37527bc717c7a55741725087bad.png)
[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment

How to restore the system of Sony laptop

Redis6.0 新功能

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

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

How to use MySQL language for row and column devices?

制造业数字化转型究竟是什么
随机推荐
Origin2018安装与使用(整理中)
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
用手机在同花顺上开户靠谱吗?这样有没有什么安全隐患
数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
模板引擎Velocity 基础
C语言输入/输出流和文件操作
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Go language source level debugger delve
Tutorial on the principle and application of database system (002) -- MySQL installation and configuration: MySQL software uninstallation (Windows Environment)
Go 语言怎么使用对称加密?
Golang爬虫框架初探
Advantages, values and risks of chain games compared with traditional games
【Hot100】20. Valid parentheses
What are the differences between PHP and DW
Template Engine Velocity Foundation
【flask入门系列】Cookie与Session
Template engine velocity Foundation
【Hot100】19. Delete the penultimate node of the linked list
Tutorial on the principle and application of database system (005) -- Yum offline installation of MySQL 5.7 (Linux Environment)