Created
December 19, 2019 17:26
Star
You must be signed in to star a gist
Questionable use of Double Checj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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