Last active
December 19, 2019 15:58
-
-
Save prydin/6f0edec36df5f3419c069ffc797e8e63 to your computer and use it in GitHub Desktop.
Typical double check
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 DoubleCheck { | |
private SomeResource myResource; | |
public SomeResource getResource() { | |
if(myResource != null) { | |
return myResource | |
} | |
synchronized(this) { | |
if(myResource != null) { | |
return myResource | |
} | |
myResource = new SomeResource(); | |
return myResource | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment