当前位置:网站首页>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
边栏推荐
- How to use MySQL language for row and column devices?
- 红队第8篇:盲猜包体对上传漏洞的艰难利用过程
- How to maintain the laptop battery
- 博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
- How to use F1 to F12 correctly on laptop keyboard
- 数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
- [JetsonNano] [教程] [入门系列] [三] 搭建TensorFlow环境
- [observation] where is the consulting going in the digital age? Thoughts and actions of softcom consulting
- Redis 分布式锁
- VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
猜你喜欢
全面看待企业数字化转型的价值
Submission lottery - light application server essay solicitation activity (may) award announcement
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
Tutorial on principles and applications of database system (006) -- compiling and installing MySQL 5.7 (Linux Environment)
Introduction to software engineering - Chapter 6 - detailed design
Kali install Nessus
Basic use of MySQL
瑞典公布决定排除华为5G设备,但是华为已成功找到新出路
Analysis of PostgreSQL storage structure
随机推荐
Activity的生命周期和启动模式详解
Apple's self-developed baseband chip failed again, which shows Huawei Hisilicon's technological leadership
AI高考志愿填报:大厂神仙打架,考生付费围观
Authentication processing in interface testing framework
SystemVerilog-结构体(二)
OJ questions related to complexity (leetcode, C language, complexity, vanishing numbers, rotating array)
How to solve the keyboard key failure of notebook computer
数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
Dataframe gets the number of words in the string
Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...
[daily question] 1175 Prime permutation
Tutorial on the principle and application of database system (005) -- Yum offline installation of MySQL 5.7 (Linux Environment)
AI college entrance examination volunteer filling: the gods of Dachang fight, and candidates pay to watch
红队第8篇:盲猜包体对上传漏洞的艰难利用过程
Is the securities account given by the head teacher of goucai school safe? Can I open an account?
Ring iron pronunciation, dynamic and noiseless, strong and brilliant, magic wave hifiair Bluetooth headset evaluation
P2592 [ZJOI2008]生日聚会(dp)
数据库系统原理与应用教程(003)—— MySQL 安装与配置:手工配置 MySQL(windows 环境)
PR basic clip operation / video export operation
Go 语言怎么优化重复的 if err != nil 样板代码?