Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bad way of doing double check
class BrokenDontUse {
private Map<String, SomeResource> aHashMap = new HashMap<>();
public SomeResource getResource(String name) {
SomeResource r = aHashMap.get(name);
if(r != null) {
return r;
}
synchronized(aHashMap) {
SomeResource r = aHashMap.get(name);
if(r != null) {
return r;
}
r = new SomeResource(name);
aHashMap.put(name, r)
return r;
}
}
}
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.