cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Hunsberger <peter.hunsber...@gmail.com>
Subject Re: Continuation invalidation strategy
Date Tue, 10 May 2005 14:37:10 GMT
On 5/10/05, Leszek Gawron <lgawron@mobilebox.pl> wrote:
> Peter Hunsberger wrote:
> > On 5/10/05, Leszek Gawron <lgawron@mobilebox.pl> wrote:
> >
> >>Peter Hunsberger wrote:
> >>
> >>>On 5/10/05, Leszek Gawron <lgawron@mobilebox.pl> wrote:
> >>>

<snip/>

> >>>
> >>>>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.

Yah,  I'd prefer not to do it this way either.  However, in my case I
couldn't find any other way to work around the CME.  If you've got the
time and the patience you could always try creating a test case for
Sun and reporting the problem :-p...

-- 
Peter Hunsberger

Mime
View raw message