forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Singleton class name has renamed to ThreadSafeLazyLoadedIvoryTower and called it from App.java
- Loading branch information
1 parent
cffe592
commit 5687976
Showing
3 changed files
with
32 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
singleton/src/main/java/com/iluwatar/ThreadSafeLazyLoadedIvoryTower.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |