Java gurus
Currently we have a HashMap<String,SomeApplicationObject> , which is often read and changed from time to time , and we have problems that occur during modification / reload, the Read operation returns null which is unacceptable.
To fix this, I have the following options:
but. Use ConcurrentHashMap
What the first choice looks like, but the operation we're talking about is reload() means clear() , followed by replaceAll() . Therefore, if Map replaceAll() clear() and pre replaceAll() , it returns null, which is undesirable. Even if I synchronize , this does not solve the problem.
C. Create another implementation based on ReentrantReadWriteLock
Where would I create the Write Lock function before reload() . It seems more appropriate, but I feel that there is something already available for this, and I do not need to reinvent the wheel.
What is the best way out?
EDIT Is any collection available with this feature?
java design locking concurrenthashmap reentrantreadwritelelock
SiB
source share