title: Struts 2 SessionMap not synchronized
body: <p>I have a long action with some insterts in a SessionMap and a very short action that read my SessionMap.
  They are like that:</p>
  
  <pre><code>public class LongAction extends ActionSupport implements SessionAware {
      private SessionMap session;
      public String index() {
          for(int i = 0 ; i &lt; 50 ; ++i) {
  
              /*
               * long treatment
               */
  
              synchronized(session) {
                  session.put("TEST", "TEST_OBJECT");
              }
           }
           return SUCCESS;
      }
      @Override
      public void setSession(Map&lt;String, Object&gt; arg0) {
          this.session = (SessionMap&lt;String, Object&gt;) arg0;
      }
  }
  </code></pre>
  
  <p>And this is my shorter action:</p>
  
  <pre><code>public class LongAction extends ActionSupport implements SessionAware {
      private SessionMap session;
      public String index() {
          synchronized (session) { 
              for(Entry&lt;String, Object&gt; e : session.entrySet()) {
                  System.out.println(e.getKey() + " --&gt; " + e.getValue());
              }
          }
          return SUCCESS;
      }
      @Override
      public void setSession(Map&lt;String, Object&gt; arg0) {
          this.session = (SessionMap&lt;String, Object&gt;) arg0;
      }
  }
  </code></pre>
  
  <p>But the entry "TEST" does not appear if I execute the second action while the first is still running.</p>
  
  <p>I tried removing synchronized blocs because I saw <a href="http://www.jarvana.com/jarvana/view/org/apache/struts/struts2-core/2.1.2/struts2-core-2.1.2-sources.jar!/org/apache/struts2/dispatcher/SessionMap.java?format=ok" rel="nofollow">here</a> that SessionMap are made for safe-threading. The problem is the same.</p>
  
  <p>PS: I am using JBoss 7.1.1</p>
  
  <p>EDIT:</p>
  
  <p>I have noticed something weird:</p>
  
  <ul>
  <li>I execute my big action (it inserts a string in my session);</li>
  <li>I execute my small action: it does not read my string in the session;</li>
  <li>I execute my big action one more time while the first is still running (it change the string in my session)</li>
  <li>I execute my small action one more time: it DOES read the new string in the session;</li>
  </ul>
  
  <p>Trace:</p>
  
  <pre><code>[stdout] (http-localhost/127.0.0.1:8781-1) 687da6e5-bd4d-474d-be60-c2d2fdc4892a
  [stdout] (http-localhost/127.0.0.1:8781-2) null
  
  [stdout] (http-localhost/127.0.0.1:8781-1) 82e6d9b7-558f-46f5-a457-b5332bb4f54e
  [stdout] (http-localhost/127.0.0.1:8781-2) 82e6d9b7-558f-46f5-a457-b5332bb4f54e
  </code></pre>
  
  <p>Moreover, the first time, session id is not the same for both actions; but the the second time, it is the same. Example:</p>
  
  <pre><code>[stdout] (http-localhost/127.0.0.1:8781-1) SessionId: j9vJzYzofPvImdrlLKKIWOGW.undefined
  [stdout] (http-localhost/127.0.0.1:8781-2) SessionId: vsXtGHmJAtaJxZcd4w9+Og6B.undefined
  
  [stdout] (http-localhost/127.0.0.1:8781-1) SessionId: vsXtGHmJAtaJxZcd4w9+Og6B.undefined
  [stdout] (http-localhost/127.0.0.1:8781-2) SessionId: vsXtGHmJAtaJxZcd4w9+Og6B.undefined
  </code></pre>
  
  <p>But, if I execute a small action before the big one, everything works well. So, I think the session needs to be initialized before because it need an action to be ended. But I do not know how.</p>