Forked from oznus/LazySingletonThreadSafe3.java
Last active
November 6, 2016 19:35
-
-
Save jemshit/bb2035e8057ff94e04c2 to your computer and use it in GitHub Desktop.
Singleton: synchronized, shared across Threads
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
public class LazySingleton { | |
private LazySingleton() { | |
} | |
private static volatile LazySingleton sInstance; | |
public static LazySingleton getInstance() { | |
if (sInstance == null) { | |
synchronized (LazySingleton.class) { | |
if (sInstance == null) { | |
sInstance = new LazySingleton(); | |
} | |
} | |
} | |
return sInstance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tutorial is here