Skip to content

Commit cffe592

Browse files
committed
New Singleton class
Thread-safe and lazy loading.
1 parent 84efa30 commit cffe592

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.iluwatar;
2+
3+
public class SingletonClass {
4+
5+
private static SingletonClass singletonInstance = null;
6+
7+
public synchronized static SingletonClass getSingleton() {
8+
/*
9+
* The instance gets created only when it is called for first time.
10+
* Lazy-loading
11+
*/
12+
if (singletonInstance == null) {
13+
singletonInstance = new SingletonClass();
14+
}
15+
16+
return singletonInstance;
17+
}
18+
}

0 commit comments

Comments
 (0)