* add state and callback pattern * add command and template-method pattern * add iterator pattern * add bridege and DI pattern * fix issue #1600 * add converter,proxy,visitor pattern * add caching,composite,delegation,dirty-flag,interpreter patterns * add dao and producer-consumer * add dto and provate class data pattern * fix #1646 png path problems * fix #1646 composite png path case problem * add abstract document pattern and version-number pattern * add ambassador pattern * add acyclic-visitor and api-gateway pattern * add abstract-factory pattern * add active-object pattern * add aggregator-microservices and arrange-act-assert pattern * update async-method-invocation pattern * add balking and business-delegate pattern * add bytecode and circuit-break pattern * update arrange/act/assert pattern problems * add csch pattern * add language code, correct pic path * #1805 update permalink Co-authored-by: Subhrodip Mohanta <subhrodipmohanta@gmail.com> Co-authored-by: Mike <admin@xiaod.info> Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
		
			
				
	
	
		
			22 lines
		
	
	
		
			949 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			949 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| ---
 | |
| layout: pattern
 | |
| title: Double Checked Locking
 | |
| folder: double-checked-locking
 | |
| permalink: /patterns/double-checked-locking/
 | |
| categories: Idiom
 | |
| language: zh
 | |
| tags:
 | |
|  - Performance
 | |
| ---
 | |
| 
 | |
| ## 含义
 | |
| 通过先测试锁定标准("锁提示")而不实际获取锁的方式来减少获取锁的开销。只有当锁定标准检查表明需要锁定时,才进行实际的锁定逻辑。
 | |
| 
 | |
| ## 类图
 | |
| 
 | |
| 
 | |
| ## 适用场景
 | |
| 在以下场景适合使用双重锁检查模式:
 | |
| 
 | |
| * 在创建对象时有存在并发的访问。如单例模式中,你想创建同一个类的单个实例,如果存在两个或更多的线程对实例进行判空,仅仅检查该该实例是否为空可能是不够的。
 | |
| * 在一个方法上存在并发访问,该方法的行为是根据一些约束条件而改变,而这些约束条件在该方法中也会发生变化。 |