Hi Jerome,
Jerome Louvel wrote:
Hi Bruno,
Thanks for the patch! A slightly modified version has been checked in
SVN trunk:
- better concurrency support
- no more addChallengeRequest() method
- use getChallengeRequests().add(..) instead)
Let me know if I broke anything :-)
Thanks, it seems to work (at least, the code I'm using doesn't seem to
be broken :-) ).
I must admit I still don't get the full picture of the way concurrency
is handled within Restlet. I wasn't quite sure what to do.
CopyOnWriteArrayList is definitely a good idea.
What I'm less clear about is the benefits of the double-check locking
(DLC) pattern. I think the intent behind this pattern was to improve
performance, but was in fact broken until the Java 5 memory model (and
the use of 'volatile', which is done here).
I don't think 'volatile' and the DCL are necessary, they could be
replaced with a simple lock. I doubt they really improve performance,
since 'volatile' effectively has some synchronisation overhead anyway.
The DCL could be removed to have a simple "synchronized(this) { if
(field==null) ... }". 'volatile' could be removed as well, if the other
accessors were also synchronised (probably better).
Best wishes,
Bruno.