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

--- Comment #8 from Philippe Mouawad <[email protected]> 2011-10-01 
11:30:39 UTC ---
(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.
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 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 ?

Regards
Philippe

-- 
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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to