当前位置:网站首页>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 .
边栏推荐
- How to send pictures to the server in the form of file stream through the upload control of antd
- Snipaste convenient screenshot software, which can be copied on the screen
- Redis 哨兵机制
- 微服务入门:Gateway网关
- Four essential material websites for we media people to help you easily create popular models
- Codeforces Round #803 (Div. 2)(A-D)
- Awk from entry to earth (15) awk executes external commands
- Conversion of yolov5 XML dataset to VOC dataset
- How to pass custom object via intent in kotlin
- How to play dapr without kubernetes?
猜你喜欢
Codeforces Round #793 (Div. 2)(A-D)
How to solve the problem of computer jam and slow down
09 softmax regression + loss function
C语言-入门-基础-语法-[变量,常亮,作用域](五)
C语言-入门-基础-语法-[主函数,头文件](二)
ArcGIS应用(二十二)Arcmap加载激光雷达las格式数据
The basic syntax of mermaid in typera
HMS core helps baby bus show high-quality children's digital content to global developers
Comparison between sentinel and hystrix
根据数字显示中文汉字
随机推荐
SSRF vulnerability exploitation - attack redis
埃氏筛+欧拉筛+区间筛
manjaro安装微信
Call Baidu map to display the current position
What if the wireless network connection of the laptop is unavailable
FOC control
Codeforces Global Round 21(A-E)
awk从入土到入门(10)awk内置函数
C # implements a queue in which everything can be sorted
The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
Three paradigms of database design
SQL statement view SQL Server 2005 version number
AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human
Bishi blog (13) -- oral arithmetic test app
Redis sentinel mechanism
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
awk从入门到入土(8)数组
Technology sharing | MySQL parallel DDL
snipaste 方便的截图软件,可以复制在屏幕上
System disk expansion in virtual machine