https://issues.apache.org/bugzilla/show_bug.cgi?id=51919

--- Comment #9 from Sebb <s...@apache.org> 2011-10-01 11:44:23 UTC ---
(In reply to comment #8)
> (In reply to comment #4)
> > Cookies are currently stored in an ArrayList. The Javadoc says:
> > 
> > "If multiple threads access an ArrayList instance concurrently, and at least
> > one of the threads modifies the list structurally, it must be synchronized
> > externally."
> > 
> > This means that all accesses must be synchronised, not just modifications.
> > 
> > The simplest way to do this would be to use Collections.synchronizedList.
> > 
> > There is a concurrent list:
> > 
> > http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CopyOnWriteArrayList.html
> > 
> > However this is only worth it if there are many more reads than writes.
> > I'm not sure that's the case with Cookies.
> > 
> > ==
> > 
> > An alternative might be to somehow defer the cookie setting to the main 
> > sample
> > thread. It should not matter if the cookies are stored after all the 
> > resources
> > have been read, because the order of responses is not guaranteed. Any 
> > cookies
> > required by the resource download must exist before the request is made.
> 
> Hello Sebb,
> I knwo about this rule regarding the need to synchronize all methods.
> But sometimes it is acceptable to only synchronize methods that modify, the
> trade-off will be that:
> - You can get obsolete informations (size, element removed)
> - But collection state will stay OK.

A thread that reads the collection can still experience
ConcurrentModificationException if it does not use synch.

> That's the approach I chose.
> 
> I used it a lot of times and I am sure it works on ArrayList. It can have
> issues with LinkerList but not arrayList.

I think you have been lucky.

> I think Collections.synchronizedList() can have performance impact, I am not
> sure I understand what you want to do, you want to modify CollectionProperty 
> to
> use a Collections.synchronizedList() wrapper ?

I know it has an impact; that's why we should not rush into partial fixes.

But I intended it only for the Cookie ArrayList.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@jakarta.apache.org
For additional commands, e-mail: notifications-h...@jakarta.apache.org

Reply via email to