title: Applying lock on HashMap
body: <p>I have a HashMap which is static and three threads which try to access HashMap simultaneously from their corresponding class`s. </p>
  
  <p>each thread task is get list value of a specified key, process some operations on the list(modify the list). and put the processed list in HashMap.</p>
  
  <p>I want to make other threads trying to access the HashMap wait until current thread finishes the processing and modifying the HashMap.</p>
  
  <p>in some situation, the flow is like this,</p>
  
  <p>thread A is retrieved HashMap, while Thread A is processing on the list of HashMap, other Thread B retrieves the HashMap and starts its processing.</p>
  
  <p>Actual behaviour has to be like:
  <code>
      Thread A -&gt; retrieves HashMap -&gt; process -&gt; put value in HashMap.
      Thread B -&gt; retrieves HashMap -&gt; process -&gt; put value in HashMap.
      Thread C -&gt; retrieves HashMap -&gt; process -&gt; put value in HashMap.</code></p>
  
  <p>logic :</p>
  
  <ol>
  <li>apply lock on HashMap</li>
  <li>retrieve.</li>
  <li>process.</li>
  <li>put into HashMap.</li>
  <li>release lock.</li>
  </ol>
  
  <p>help me in converting the logic to code, or any suggestions are accepted with smile. </p>