cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Kuhnle <>
Subject Re: [IMP] synchronization on session object in Cocoon
Date Sun, 15 May 2005 16:05:47 GMT
Am I not getting it, or is the implementation broken (see below)?

/** The map to assure 1:1-mapping of server sessions and Cocoon session 
wrappers */
private static final Map sessions = Collections.synchronizedMap(new 

public Session getSession(boolean create) {
        javax.servlet.http.HttpSession serverSession = 
                HttpSession session;
        if (serverSession != null) {
        // no need to lock the map - it is synchronized
            // synch on server session assures only one wrapper per 
            synchronized (serverSession) {
                // retrieve existing wrapper
                        session = 

//----> What if the map does not contain the session? 
sessions.get(serverSessions) returns null, resulting in a 
NullPointerException in the second get().

//----> Why not synchronize on the map, and not the serverSession. Right 
now, we run through 3 synchronize blocks: synchronized(serverSession), 
session.get(...) and sessions.put(...). Wouldn't replacing 
synchronized(serverSession) with synchronized(sessions) and using an 
unsynchronized map suffice? Resulting in only one synchronized block?

                        if (session == null) {
                        // create new wrapper
                        session = new HttpSession(serverSession);
                        sessions.put(serverSession, new 
        } else {
        // invalidate
            session = null;
        return session;


View raw message