diff --git a/notes/01-singleton-builder.md b/notes/01-singleton-builder.md index d4d57fa..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 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)