I\'ve got a web application where people ask for resources. This resources are cached using a synchronized hash map for efficiency. The problem here is when two different re
Your code looks ok, except that you are synchronizing more than actually required:
Using a ConcurrentHashMap
instead of a synchronized HashMap
would allow multiple invocations of the get method without locking.
Synchronizing on this
instead of resources
is probably not necessary, but it depends on the rest of your code.