From 30c3cbc795cbf201f1c396a362509a724721f534 Mon Sep 17 00:00:00 2001 From: tonyabraham115 <124860157+tonyabraham115@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:49:25 +0530 Subject: [PATCH 1/2] Corrects conceptual error --- notes/01-singleton-builder.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notes/01-singleton-builder.md b/notes/01-singleton-builder.md index d4d57fa..da5a504 100644 --- a/notes/01-singleton-builder.md +++ b/notes/01-singleton-builder.md @@ -111,7 +111,7 @@ public class Database { ### Double-checked locking -The above code is thread-safe. However, it is not efficient. If two threads call the getInstance() method at the same time, both threads will check if the instance variable is null. Both threads will find that the instance variable is null. Both threads will wait for the lock to be released. Once the lock is released, one thread will create a new instance of the Database class. The other thread will wait for the lock to be released. Once the lock is released, it will create a new instance of the Database class. This will result in two instances of the Database class. To make the above code efficient, we can use double-checked locking. +The above code is thread-safe. However, it is not Efficient. If a database instance has been created, and two threads try to access it, only one thread can call getInstance method, and the other must wait until the lock is released. To make the above code efficient, we can use double-checked locking. ```java public class Database { @@ -266,4 +266,4 @@ Database database = new Database.DatabaseBuilder() ## Reading list * [Telescoping constructor anti-pattern](https://www.vojtechruzicka.com/avoid-telescoping-constructor-pattern/) -* [Why objects should be immutable?](https://octoperf.com/blog/2016/04/07/why-objects-must-be-immutable) \ No newline at end of file +* [Why objects should be immutable?](https://octoperf.com/blog/2016/04/07/why-objects-must-be-immutable) From a9167a2008f683bf161a6c2f04de1b55a12cc263 Mon Sep 17 00:00:00 2001 From: tonyabraham115 <124860157+tonyabraham115@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:56:34 +0530 Subject: [PATCH 2/2] Corrects typo --- notes/01-singleton-builder.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/01-singleton-builder.md b/notes/01-singleton-builder.md index da5a504..c65dc77 100644 --- a/notes/01-singleton-builder.md +++ b/notes/01-singleton-builder.md @@ -111,7 +111,7 @@ public class Database { ### Double-checked locking -The above code is thread-safe. However, it is not Efficient. If a database instance has been created, and two threads try to access it, only one thread can call getInstance method, and the other must wait until the lock is released. To make the above code efficient, we can use double-checked locking. +The above code is thread-safe. However, it is not efficient. If a database instance has been created, and two threads try to access it, only one thread can call getInstance method, and the other must wait until the lock is released. To make the above code efficient, we can use double-checked locking. ```java public class Database {