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