当前位置:网站首页>[designmode] singleton pattern
[designmode] singleton pattern
2022-06-30 23:46:00 【weixin_ forty-three million two hundred and twenty-four thousan】
1. Introduction to singleton design patterns
So called class singleton design pattern , Is to take certain methods to ensure that in the whole software system , There can only be one object instance for a class , And this class only provides a method to get its object instance ( Static methods ).
such as Hibernate Of SessionFactory, It acts as a proxy for the datastore source , And responsible for creating Session object .SessionFactory It's not lightweight , In general , A project usually only needs one SessionFactory Is enough , This will be used in singleton mode .
2. There are eight ways to design singleton
There are eight ways of singleton mode :
1) Hungry Chinese style ( static const )
2) Hungry Chinese style ( Static code block )
Slacker type ( Thread unsafe )
Slacker type ( Thread safety , Synchronization method )
Slacker type ( Thread safety , Synchronization code block )
6) Double check
7) Static inner class
8) enumeration
3. Hungry Chinese style ( static const )
Hungry Chinese style ( static const ) Application example
Steps are as follows : Silicon Valley Java Design patterns
Constructor privatization ( prevent new )
Create objects inside the class
Expose a static public method .getInstance
Code implementation
边栏推荐
- E-commerce seckill system
- LVM snapshot: preparation of backup based on LVM snapshot
- 如何关闭一个开放的DNS解析器
- Solution to the conflict between unique index and logical deletion
- One revolution, two forces and three links: the "carbon reduction" road map behind the industrial energy efficiency improvement action plan
- Ctfshow framework reproduction
- Detailed explanation of conv2d -- use in arrays and images
- Error when starting PHP: [pool www] cannot get uid for user '@php_ fpm_ [email protected]’
- To tell you the truth, ThreadLocal is really not an advanced thing
- 5g smart building solution 2021
猜你喜欢

Analysis of 8253a register

8253A寄存器浅析

Gateway service gateway

Introduction to machine learning compilation course learning notes lesson 2 tensor program abstraction

5G智慧建筑解决方案2021

Development of wireless U-shaped ultrasonic electric toothbrush

Ride: get picture Base64

KubeVela 1.4:让应用交付更安全、上手更简单、过程更透明

Zero sample and small sample learning

企业出海数字化转型解决方案介绍
随机推荐
什么是SRM系统,如何规范公司内部采购流程
Sm2246en+ SanDisk 15131
Bridge emqx cloud data to AWS IOT through the public network
Maxpool2d explanation -- Application in arrays and images
8253A寄存器浅析
CTFSHOW权限维持篇
Two way data binding in wechat applet
Flitter - sort list sort
Is it safe to open a stock account of Huatai Securities online?
如何使用 DataAnt 监控 Apache APISIX
异步过渡方案—Generator
Never use redis expired monitoring to implement scheduled tasks!
1175. prime number arrangement / Sword finger offer II 104 Number of permutations
Introduction to digital transformation solutions for enterprises going to sea
Why should VR panoramic shooting join us? Leverage resources to achieve win-win results
Online customer service chat system source code_ Beautiful and powerful golang kernel development_ Binary operation fool installation_ Attached construction tutorial
让企业数字化砸锅和IT主管背锅的软件供应链安全风险指北
Five minutes to understand the exploratory test
shell 同时执行多任务下载视频
Query points in MATLAB Delaunay triangulation