Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 64145 invoked from network); 10 May 2005 14:33:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 May 2005 14:33:05 -0000 Received: (qmail 58379 invoked by uid 500); 10 May 2005 14:36:19 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 58281 invoked by uid 500); 10 May 2005 14:36:18 -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 58240 invoked by uid 99); 10 May 2005 14:36:17 -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 v07274.home.net.pl (HELO v07274.home.net.pl) (212.85.125.162) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 10 May 2005 07:36:15 -0700 Received: from sj162.internetdsl.tpnet.pl (HELO ?192.168.1.62?) (lgawron.mobilebox@home@80.55.87.162) by matrix15.home.net.pl with SMTP; Tue, 10 May 2005 14:32:42 -0000 Message-ID: <4280C60A.6050205@mobilebox.pl> Date: Tue, 10 May 2005 16:32:42 +0200 From: Leszek Gawron 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: Continuation invalidation strategy References: <4275DF46.2020408@apache.org> <4275FA3B.2070402@mobilebox.pl> <42762406.1010402@reverycodes.com> <42765D4E.4070503@mobilebox.pl> <42766258.2050408@reverycodes.com> <4280BDE1.80307@mobilebox.pl> <4280C328.2040000@mobilebox.pl> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Peter Hunsberger wrote: > On 5/10/05, Leszek Gawron wrote: > >>Peter Hunsberger wrote: >> >>>On 5/10/05, Leszek Gawron wrote: >>> >>> >>>>Vadim Gritsenko wrote: >>>> >>>> >>>>>Leszek Gawron wrote: >>>>> >>>>> >>>>> >>>>>>Vadim Gritsenko wrote: >>>>>> >>>>>> >>>>>> >>>>>>>If you want to tinker with ContinuationsManagerImpl, take a look at: >>>>>>> http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=111323704203839 >>>>>> >>>>>> >>>>>>Strange I missed that post .. >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>>Unsynchronized access to WebContinuationsHolder from >>>>>>>invalidateContinuations() simultaneously with write access in >>>>>>>generateContinuation() should reliably cause >>>>>>>ConcurrentModificationException. >>>>>> >>>>>> >>>>>>I do not quite get the problem. Doesn't it cause >>>>>>ConcurrentModificationException now? >>>>> >>>>> >>>>>It should - I've not seen it though. >>>>> >>>>> >>>>> >>>>> >>>>>>Other thing is how can invalidateContinuations and >>>>>>generateContinuation be run concurrently. invalidateContinuations is >>>>>>invoked only for expired sessions - how can new continuation be >>>>>>generated for that session? >>>>> >>>>> >>>>>Bad example then. Here is better one: >>>>> >>>>> invalidateContinuations() gets Iterator on continuationsHolder.holder >>>>>map. >>>>> invalidateContinuations() calls _invalidate() >>>>> _invalidate() calls disposeContinuation() >>>>> disposeContinuation() modifies continuationsHolder.holder map. >>>>> >>>>>After that, >>>>> >>>>> invalidateContinuations() calls next() and causes >>>>>ConcurrentModificationException. >>>>> >>>>>Seems to me invalidateContinuations() should have while(!empty) loop >>>>>instead of iterator. >>>> >>>>Still HashMap has no interface other than iterator to get it's contents. >>>>you can either iterate through hashMap.iterator() or >>>>hashMap().keySet().iterator() - no difference, both are synced. >>>> >>>>any ideas? >>> >>> >>>I've seen this problem with the 1.4.2_02 JDK, don't know if it exists >>>elsewhere. The Sun docs claim syncrhonizing on the hashMap should >>>solve the problem but it doesn't. The solution I came up with was to >>>build an array instead of using an iterator, eg: >>> >>> Object[] list = targetObjects.keySet().toArray(); >>> >>> >>>Peter Hunsberger >> >>I doubt it will work: >> >>AbstractCollection.toArray() is in fact the implementation for >>HashMap.KeySet.toArray(): >> >> public Object[] toArray() { >> Object[] result = new Object[size()]; >> Iterator e = iterator(); >> for (int i=0; e.hasNext(); i++) >> result[i] = e.next(); >> return result; >> } >> >>also uses iterator. > > > Building the array and then walking it is different than using the > iterator to walk the key set directly. The exception comes when you > touch an object in the key set that is accessed through the iterator. > With the array, you're no longer using the iterator at the time you > touch the object. As a result you don't get the exception (not that > you should have gotten it in the first place). > I see. I'll change the code then. I do not know how memory intensive .toArray() in production environment might be. There may be a lot of continuations to clear on session invalidation. -- Leszek Gawron lgawron@mobilebox.pl IT Manager MobileBox sp. z o.o. +48 (61) 855 06 67 http://www.mobilebox.pl mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65