2014-10-13 22:15:45 -07:00
|
|
|
package com.iluwatar;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Thread-safe Singleton class.
|
2014-11-26 22:45:47 +02:00
|
|
|
* The instance is lazily initialized and thus needs synchronization
|
|
|
|
* mechanism.
|
2014-10-13 22:15:45 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ThreadSafeLazyLoadedIvoryTower {
|
|
|
|
|
|
|
|
private static ThreadSafeLazyLoadedIvoryTower instance = null;
|
2014-11-05 21:28:48 +02:00
|
|
|
|
|
|
|
private ThreadSafeLazyLoadedIvoryTower() {
|
|
|
|
}
|
2014-10-13 22:15:45 -07:00
|
|
|
|
|
|
|
public synchronized static ThreadSafeLazyLoadedIvoryTower getInstance() {
|
|
|
|
/*
|
|
|
|
* The instance gets created only when it is called for first time.
|
|
|
|
* Lazy-loading
|
|
|
|
*/
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new ThreadSafeLazyLoadedIvoryTower();
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|