ConcurrentModificationException in java.util.ServiceLoader (not a multi-thread issue)
Alan Bateman
Alan.Bateman at oracle.com
Tue Feb 24 09:44:33 UTC 2015
On 24/02/2015 09:32, Martin Desruisseaux wrote:
> :
> One use case is that in a multi-thread environment, this bug implies
> that it is not sufficient to synchronize all direct and indirect
> (through Iterator) usages of ServiceLoader. We must synchronize the
> entire iteration loop for preventing other threads to start a new
> iteration before we finished the current one. This can be annoying if
> the work to do between two calls to Iterator.hasNext() / next() is long.
> Sometime it is not possible to synchronize the entire loop if we do not
> control the iteration (i.e. if we advance in the iterator only when the
> user invokes some method). The later case can be a problem even in
> mono-thread application.
True although I don't think it's ever come up before (at least I can't
find any bugs/reports on this). It's good to bring it now. I do think
that ServiceLoader will be most replaced in JDK 9 anyway.
-Alan
More information about the core-libs-dev
mailing list