Bad way of doing 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 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