commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Berin Loritsch" <>
Subject RE: [SUBMIT][Collections] Buffer stuff from Avalon
Date Thu, 27 Jun 2002 21:01:40 GMT
> From: Michael A. Smith [] 
> On Thu, 27 Jun 2002, Stephen Colebourne wrote:
> > In the synchronizedBuffer implementation, the iterator() 
> method should 
> > probably NOT be synchronized. The equivalent in 
> java.util.Collections 
> > isn't and has a suitable comment instead.
> I've always thought it was weird that the interator was 
> unsynchronized.  
> There's no reason each method on the iterator can't 
> synchronize on the 
> appropriate object to ensure consistency in a multi-threaded 
> environment.  But, alas, Sun decided against it and just added a 
> comment.  I haven't had a chance to look at what Paul put 
> together, but 
> I'm inclined to agree with Stephen here that we should behave 
> similarly 
> to java.util.Collections.synchronizedFoo(). 

Consider how the iterator is used.  It is _supposed_ to be
a short lived object that is used within one thread.  It is
typically used for the quick loop like this:

Iterator it = l_buffer.iterator();

while( it.hasNext() )
    Object o =;
    // do stuff

If separate threads are using the same buffer/list, they
usually have their own iterators.  Kind of like the JDK 1.4
NIO stuff.  Each listening thread has its own selector,
and operates on it.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message