1. Introduction
Let's try and understand Singleton design pattern.
Note: We will be using Spring Boot for all code examples, there is no reason for it, it's just the way we code :)
2. Implementation
Let's try to implement the class.
2.1 Eager Implementation
2.2 LazyLoad Implementation
Let's delay the class creation until accessed :
However, this class has one flaw, can you spot?
It is not thread safe.
2.3 LazyLoad Threadsafe
Let's make class (instance creation) thread safe:
No comments:
Post a Comment