New Singleton class

Thread-safe and lazy loading.
This commit is contained in:
Sujan Reddy Annem 2014-10-13 13:24:18 -07:00
parent 84efa3039f
commit cffe592c9c

View File

@ -0,0 +1,18 @@
package com.iluwatar;
public class SingletonClass {
private static SingletonClass singletonInstance = null;
public synchronized static SingletonClass getSingleton() {
/*
* The instance gets created only when it is called for first time.
* Lazy-loading
*/
if (singletonInstance == null) {
singletonInstance = new SingletonClass();
}
return singletonInstance;
}
}