Skip to content

Instantly share code, notes, and snippets.

@prydin
Last active December 19, 2019 15:58
  • 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/6f0edec36df5f3419c069ffc797e8e63 to your computer and use it in GitHub Desktop.
Typical double check
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