Hello Peter Le 24/02/15 13:49, Peter Levart a écrit : > You could synchronize on the entire loop and just copy over the > service objects to another collection (say ArrayList).
Right, but I would like to keep the laziness instantiation behaviour. > If you really must combine laziness of constructing service objects > with concurrent iterations, you can wrap the ServiceLoader.iterator() > with the following: > > public class BufferedConcurrentIterable<E> implements Iterable<E> { > (...snip...) Many thanks for your help. This is indeed what I did yesterday :-). But given that the current ServiceLoader behaviour results in random ConcurrentModificationException in some multi-threads environments, this can mislead the users who believe that they have a synchronization error in their own code before they realize that the issue is in ServiceLoader itself. Martin