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. What we
probably need is a Map mapping the server sessions to the wrapper objects.
WDYT?
Joerg
[1] http://svn.apache.org/viewcvs.cgi/cocoon/tags/RELEASE_2_1_7/src/java/org/
apache/cocoon/environment/http/HttpRequest.java?rev=158761&view=markup