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