Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Doble check singleton implementation
@SuppressWarnings({"unused", "FieldCanBeLocal", "WeakerAccess"})
public final class Singleton {
private static volatile Singleton ourInstance = null;
public static Singleton getInstance() {
if (ourInstance == null) {
synchronized (Singleton.class) {
if (ourInstance == null) {
ourInstance = new Singleton();
}
}
}
return ourInstance;
}
private Singleton() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment