Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 31727 invoked from network); 17 Apr 2005 05:34:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Apr 2005 05:34:33 -0000 Received: (qmail 74824 invoked by uid 500); 17 Apr 2005 05:34:30 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 74743 invoked by uid 500); 17 Apr 2005 05:34:29 -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 Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 74723 invoked by uid 99); 17 Apr 2005 05:34:29 -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; Sat, 16 Apr 2005 22:34:28 -0700 Received: from mail5.dslextreme.com (unknown [192.168.7.93]) by mailgate1.dslextreme.com (Postfix) with SMTP id 17CA86300D2 for ; Sat, 16 Apr 2005 22:30:40 -0700 (PDT) Received: (qmail 26757 invoked from network); 17 Apr 2005 05:34:18 -0000 Received: from unknown (HELO [192.168.10.10]) (66.51.196.164) by mail5.dslextreme.com with SMTP; Sat, 16 Apr 2005 22:34:18 -0700 Message-ID: <4261F55A.5010008@dslextreme.com> Date: Sat, 16 Apr 2005 22:34:18 -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: Problem with sharing sessions/ multithreading 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 1. Is it my imagination or was the same message posted 5 times? 2. If I understand correctly, the problem is that multiple users are getting the same DOM object? a. Question: Why do you have two actions that do essentially the same thing? b. By the way, even though you declared them ThreadSafe they clearly are not. It is possible for the web-browser to issue two requests at the same time to Cocoon for the same user, depending on how the html page is constructed, in which case both of these actions could execute at the same time. c. What is the purpose of synchronizing the object returned by newInstance? That is a local variable and if each call to newInstance returns a different object, this will accomplish nothing. If you want to serialize the call to newDocument then you should refactor this whole block of code in a method in a utility class and then always call that method from all your actions to get the document. It should do something like: private static final String LOCK = "Lock"; Document getDocument() { Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Document doc = (Document)session.getAttribute("myAttribute"); if (doc == null) { // It is possible for more than one thread to get here at the same time with doc == null syncronize(LOCK); { // So check again. Only the first caller should actually create the document. doc = (Document)session.getAttribute("myAttribute"); if (doc == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); doc = dbf.newDocumentBuilder().newDocument(); session.setAttribute("myAttribute", doc); } } } return doc; }