title: List in ConcurrentHashMap
body: <pre><code>public static ConcurrentHashMap&lt;Integer,Session&gt; USER_SESSIONS...    
  </code></pre>
  
  <p>Everything works fine. But what if the system is allowed to be authorized two sessions with the same user ID? Well, that is roughly two PCs sitting under the same account, but different session.
  Tried to do so:</p>
  
  <pre><code>ConcurrentHashMap&lt;Integer,List&lt;Session&gt;&gt; USER_SESSIONS....
  
  ...............
  
  private void addUser(Session session){
     List&lt;Session&gt; userSessions = Server.USER_SESSIONS.get(session.mUserId);
  
     if(userSessions==null){
         userSessions = new List&lt;Session&gt;();
         userSessions.add(session);
         Server.USER_SESSIONS.put(session.getUserId(),userSessions);
     }else{
         userSessions.add(session);
     }
  }
  
  private void removeUser(Session session){
    List&lt;Session&gt; userSessions = Server.USER_SESSIONS.get(session.mUserId);
  
    if(userSessions!=null){
         userSessions.remove(session);
         if(userSessions.size()==0)
         {
             Server.USER_SESSIONS.remove(session.getUserId());
         }
    }
  }
  
  .................
  
  private void workWithUsers(int userId){
      for(Session session : Server.USER_SESSIONS.get(userId))
      {
         &lt;do it!&gt;
      }
  }
  </code></pre>
  
  <p>Naturally, all these methods can be called from different threads, and I'm getting errors related to List . And this is natural, because while I have foreach-list session can be removed by removeUser from another thread. What to do? How to make so that-be at work with a list of all the threads List  waited until it occupies the thread is finished with it? Yet done so :)</p>
  
  <pre><code>public static ConcurrentHashMap&lt;Integer,ConcurrentHashMap&lt;Session,Session&gt;&gt; USER_SESSIONS
  </code></pre>
  
  <p>Since ConcurrentHashMap thread safe. But I think it's crooked decision. Many thanks in advance for your help!</p>
  
  <p>P.S: JRE 1.<strong>6</strong></p>
  
  <p>Please sorry for my English.</p>