Lazy instantiation using double locking mechanism
by, 03-09-2012 at 06:45 PM (1121 Views)
The standard implementation is a thread-safe implementation. However, it is not the best implementation as when you talk about performance, the synchronization is quite expensive.When the object gets initialized, there is no need to check the synchronized method getInstance for synchronization. When singleton object has already been created, just return it without making use of synchronized block.
When for the first time getInstance() method is called, singleton instance is created. This is known as lazy instantiation which makes it sure that creation of the singleton instance takes place just when it is required.