当前位置:网站首页>Talk about single case mode
Talk about single case mode
2022-07-04 08:47:00 【,, country】
java Use a class in , Instantiate only once
The answer is : The singleton pattern .
The specific code is
public class A{
private A(){}// Set constructor to private, Other classes can no longer call instantiation
private static A instance=new A();// The only instance , add static attribute
public static A getInstance(){// Other class calls A The only access to , It's also static attribute , The calling method is A.getInstance()
return instance;
}
}
advantage :
First of all 、 Control the use of resources , Control the concurrent access of resources through thread synchronization ;
second 、 Control the number of instances generated , To save resources .
Third 、 To use as a medium of communication , That is data sharing , It can be done without a direct connection , Allow multiple unrelated threads or processes to communicate with each other .
边栏推荐
- [Chongqing Guangdong education] National Open University spring 2019 455 logistics practice reference questions
- [attack and defense world | WP] cat
- C#实现一个万物皆可排序的队列
- PHP session variable passed from form - PHP
- Basic discipline formula and unit conversion
- awk从入门到入土(18)gawk线上手册
- The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
- yolov5 xml数据集转换为VOC数据集
- A single element in an ordered array
- Codeforces Global Round 21(A-E)
猜你喜欢
Snipaste convenient screenshot software, which can be copied on the screen
C, Numerical Recipes in C, solution of linear algebraic equations, Gauss Jordan elimination method, source code
Newh3c - network address translation (NAT)
Collections in Scala
Educational Codeforces Round 119 (Rated for Div. 2)
ctfshow web255 web 256 web257
Sequence model
MySQL relearn 1-centos install mysql5.7
FOC control
Leetcode topic [array] -136- numbers that appear only once
随机推荐
Newh3c - network address translation (NAT)
2022 examination questions for safety managers of metal and nonmetal mines (underground mines) and examination papers for safety managers of metal and nonmetal mines (underground mines)
Awk from entry to earth (8) array
Educational Codeforces Round 115 (Rated for Div. 2)
swatch
awk从入门到入土(12)awk也可以写脚本,替代shell
If the array values match each other, shuffle again - PHP
What sparks can applet container technology collide with IOT
From scratch, use Jenkins to build and publish pipeline pipeline project
Live in a dream, only do things you don't say
System disk expansion in virtual machine
How college students choose suitable computers
Internal learning
FOC control
老掉牙的 synchronized 锁优化,一次给你讲清楚!
DM8 database recovery based on point in time
Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
What should I do if there is a problem with the graphics card screen on the computer
What if I forget the router password
Go zero micro service practical series (IX. ultimate optimization of seckill performance)