Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 86493 invoked from network); 16 May 2005 07:29:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 May 2005 07:29:49 -0000 Received: (qmail 80775 invoked by uid 500); 16 May 2005 07:29:23 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 80647 invoked by uid 500); 16 May 2005 07:29:22 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 80626 invoked by uid 99); 16 May 2005 07:29:21 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from mailgate1.dslextreme.com (HELO mailgate1.dslextreme.com) (66.51.199.94) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 16 May 2005 00:29:19 -0700 Received: from mail5.dslextreme.com (unknown [192.168.7.93]) by mailgate1.dslextreme.com (Postfix) with SMTP id 8C493630086 for ; Mon, 16 May 2005 00:28:57 -0700 (PDT) Received: (qmail 17807 invoked from network); 16 May 2005 07:29:05 -0000 Received: from unknown (HELO [192.168.10.10]) (66.51.196.164) by mail5.dslextreme.com with SMTP; Mon, 16 May 2005 00:29:05 -0700 Message-ID: <42884BC1.3030706@dslextreme.com> Date: Mon, 16 May 2005 00:29:05 -0700 From: Ralph Goers User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: [IMP] synchronization on session object in Cocoon References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-DSLExtreme-MailGate-Information: Please contact the ISP for more information X-DSLExtreme-MailGate: Found to be clean X-MailScanner-From: ralph.goers@dslextreme.com X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Please update from svn and review the changes. Ralhp Jochen Kuhnle wrote: >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 >WeakHashMap()); > >public Session getSession(boolean create) { > javax.servlet.http.HttpSession serverSession = >this.req.getSession(create); > HttpSession session; > if (serverSession != null) { > // no need to lock the map - it is synchronized > // synch on server session assures only one wrapper per >session > synchronized (serverSession) { > // retrieve existing wrapper > session = >(HttpSession)((WeakReference)sessions.get(serverSession)).get(); > >//----> 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 >WeakReference(session)); > } > } > } else { > // invalidate > session = null; > } > > return session; >} > >Regards, >Jochen > >