From d1e1be13afe00b1637cddbc310b9d7fe64cc2012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20Ayta=C5=9F?= Date: Mon, 8 Sep 2014 15:33:36 +0100 Subject: [PATCH] Added Intent to the Double Checked Locking. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 00043a233..e032922e9 100644 --- a/README.md +++ b/README.md @@ -239,7 +239,10 @@ * many distinct and unrelated operations need to be performed on objects in an object structure, and you want to avoid "polluting" their classes with these operations. Visitor lets you keep related operations together by defining them in one class. When the object structure is shared by many applications, use Visitor to put operations in just those applications that need them * the classes defining the object structure rarely change, but you often want to define new operations over the structure. Changing the object structure classes requires redefining the interface to all visitors, which is potentially costly. If the object structure classes change often, then it's probably better to define the operations in those classes -![alt text](https://github.com/iluwatar/java-design-patterns/blob/master/double-checked-locking/etc/double_checked_locking.jpg "Double Checked Locking") +##Double Checked Locking +**Intent:** Reduce the overhead of acquiring a lock by first testing the locking criterion (the "lock hint") without actually acquiring the lock. Only if the locking criterion check indicates that locking is required does the actual locking logic proceed. + +![alt text](https://github.com/yusufaytas/java-design-patterns/blob/master/double-checked-locking/etc/double_checked_locking.jpeg "Double Checked Locking") **Applicability:** Use the Double Checked Locking pattern when * there is a concurrent access in object creation, e.g. singleton, where you want to create single instance of the same class and checking if it's null or not maybe not be enough when there are two or more threads that checks if instance is null or not.