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
  • Select an option

  • Save jemshit/bb2035e8057ff94e04c2 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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