Java Gurus,
Currently we have a HashMap<String,SomeApplicationObject>
which is being read frequently and modified occasionally and we are having issues that during the modification/reloading, Read operation returns null
which is not acceptable.
To fix this I have following options:
A. Use ConcurrentHashMap
Which looks like the first choice but the operation which we are talking about is reload()
- means clear()
followed by replaceAll()
. So if the Map
is read post clear()
and pre replaceAll()
it returns null which is not desirable. Even if I synchronize
this doesn't resolves the issue.
B. Create another implementation based upon ReentrantReadWriteLock
Where I would create acquire Write Lock
before reload()
operation. This seems more appropriate but I feel there must be something already available for this and I need not to reinvent the wheel.
What is the best way out?
EDIT Is any Collection already available with such feature?