I have a long action with some insterts in a SessionMap and a very short action that read my SessionMap. They are like that:
public class LongAction extends ActionSupport implements SessionAware {
private SessionMap session;
public String index() {
for(int i = 0 ; i < 50 ; ++i) {
/*
* long treatment
*/
synchronized(session) {
session.put("TEST", "TEST_OBJECT");
}
}
return SUCCESS;
}
@Override
public void setSession(Map<String, Object> arg0) {
this.session = (SessionMap<String, Object>) arg0;
}
}
And this is my shorter action:
public class LongAction extends ActionSupport implements SessionAware {
private SessionMap session;
public String index() {
synchronized (session) {
for(Entry<String, Object> e : session.entrySet()) {
System.out.println(e.getKey() + " --> " + e.getValue());
}
}
return SUCCESS;
}
@Override
public void setSession(Map<String, Object> arg0) {
this.session = (SessionMap<String, Object>) arg0;
}
}
But the entry "TEST" does not appear if I execute the second action while the first is still running.
I tried removing synchronized blocs because I saw here that SessionMap are made for safe-threading. The problem is the same.
PS: I am using JBoss 7.1.1
EDIT:
I have noticed something weird:
- I execute my big action (it inserts a string in my session);
- I execute my small action: it does not read my string in the session;
- I execute my big action one more time while the first is still running (it change the string in my session)
- I execute my small action one more time: it DOES read the new string in the session;
Trace:
[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
Moreover, the first time, session id is not the same for both actions; but the the second time, it is the same. Example:
[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
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.