title: Thread safe iterating over LinkedHashMap
body: <p>I have a private LinkedHashMap which is used for reading (only for reading) from different threads:</p>
  
  <pre><code>class foo {
  
    private LinkedHashMap map = ...;
  
  
    public publicMethodCalledFromDifferentThreads() {
  
       for (Object foo : map) {
          ...
       }
    }
  }
  </code></pre>
  
  <p>This implementation is not thread safe and so the <code>for</code> loop can't behave correctly. I tried to find a solution by myself and the only thing I came up with is the following:</p>
  
  <pre><code>class foo {
  
    private LinkedHashMap map = ...;
    private Map.Entry[] mapEntries = map.entrySet().toArray() ...;
  
    public publicMethodCalledFromDifferentThreads() {
  
       for (int i = 0; i &lt; mapEntries.length; i++) {
          mapEntries[i]...
          ...
       }
    }
  }
  </code></pre>
  
  <p>So in the end I need to have two variables and the iteration gets really complex. What would be the nicest way to do this?</p>
  
  <p>Thanks!</p>