Singleton pattern can make a class to be created the only one instance.
First, writing a singleton class.
Then you will do this to use it. And this way causes duplicate instances when you call new many times.
So we modify design to this.
But it still happened duplicate instances when we call several times of Singleton.getInstance();.
Next, we modify it again.
Do we finish it? No. Let us think about multi-thread situation instead of single-thread.
Happened duplicate instances again! Let us added synchronized to protect.
Now, duplicate instances problem is solved. And the new problem is performance.
If there are many threads running, a thread need wait front thread until it finished work.
So we can do this. Initialed the Singleton class only once when program on started.