Skip to content

Instantly share code, notes, and snippets.

@jemshit
Forked from oznus/LazySingletonThreadSafe3.java
Last active November 6, 2016 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jemshit/bb2035e8057ff94e04c2 to your computer and use it in GitHub Desktop.
Save jemshit/bb2035e8057ff94e04c2 to your computer and use it in GitHub Desktop.
Singleton: synchronized, shared across Threads
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;
}
}
@jemshit
Copy link
Author

jemshit commented Feb 21, 2016

Tutorial is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment