Skip to content

Instantly share code, notes, and snippets.

@prydin
Created December 19, 2019 17:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save prydin/fa024f1434e7436e25fa387cef1404eb to your computer and use it in GitHub Desktop.
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