Created
April 14, 2018 04:20
-
-
Save surajdubey/c5cfa215c894364951890047b664826d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class ThreadSafeSingletonWithDoubleCheckedLocking { | |
| private static ThreadSafeSingletonWithDoubleCheckedLocking threadSafeSingleton; | |
| /** | |
| * private constructor so that other classes can't | |
| * instantiate it through constructor | |
| * any instantiation while creating new singleton instance should come here | |
| */ | |
| private ThreadSafeSingletonWithDoubleLocking() {} | |
| public static synchronized ThreadSafeSingletonWithDoubleCheckedLocking getInstance() { | |
| if(threadSafeSingleton == null) { | |
| synchronized(ThreadSafeSingletonWithDoubleCheckedLocking.class) { | |
| threadSafeSingleton = new ThreadSafeSingletonWithDoubleCheckedLocking(); | |
| } | |
| } | |
| return threadSafeSingleton; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment