Thread-safe Singleton class

New Singleton class name has renamed to ThreadSafeLazyLoadedIvoryTower
and called it from App.java
This commit is contained in:
Sujan Reddy Annem
2014-10-13 22:15:45 -07:00
parent cffe592c9c
commit 5687976a91
3 changed files with 32 additions and 20 deletions

View File

@ -0,0 +1,23 @@
package com.iluwatar;
/**
*
* Thread-safe Singleton class.
*
*/
public class ThreadSafeLazyLoadedIvoryTower {
private static ThreadSafeLazyLoadedIvoryTower instance = null;
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;
}
}