Joerg Heinicke wrote:
Hello,
I think I have found a more general problem with synchronization in Cocoon. I tried to solve my problem with synchronization in flow script with an intermediate object. This object handles the synchronized instantiation of my component. Unfortunately I found out that "synchronized (session) { ... }" still did not work - two requests of the same session run into that block at the same time. I did some remote debugging. First I thought the reason is in flow script as it also wraps the session, but it unwraps it later. The reason is in HttpRequest class. Have a look at the code [1]:
public Session getSession(boolean create) { javax.servlet.http.HttpSession serverSession = this.req.getSession(create); if ( null != serverSession) { if ( null != this.session ) { if ( this.session.wrappedSession != serverSession ) { // update wrapper this.session.wrappedSession = serverSession; } } else { // new wrapper this.session = new HttpSession( serverSession ); } } else { // invalidate this.session = null; } return this.session; }
As you can see on every request a new wrapper is instantiated which is really bad. It is not possible to synchronize on Cocoon session objects.
Wow, very good point!
What we probably need is a Map mapping the server sessions to the wrapper objects.
Or more simply we could store the wrapper in the session itself using an attribute. That way it would be guaranteed to be created only once.
Sylvain
-- Sylvain Wallez Anyware Technologies http://apache.org/~sylvain http://anyware-tech.com Apache Software Foundation Member Research & Technology Director
