View RSS Feed

Design Patterns

Lazy instantiation using double locking mechanism

Rate this Entry
by , 03-09-2012 at 06:45 PM (1151 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.

Submit "Lazy instantiation using double locking mechanism" to Facebook Submit "Lazy instantiation using double locking mechanism" to Digg Submit "Lazy instantiation using double locking mechanism" to del.icio.us Submit "Lazy instantiation using double locking mechanism" to StumbleUpon Submit "Lazy instantiation using double locking mechanism" to Google

Comments