Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Questionable use of Double Checj
class QuestionableUseOfDoubleCheck {
private long firstAccess = -1;
public long accessSomething() {
if (firstAccess != -1) {
return this.firstAccess;
}
synchronized (this) {
if (this.firstAccess != -1) {
return this.firstAccess;
}
this.firstAccess = System.currentTimeMillis();
return this.firstAccess;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.