[jboss-dev] concurrency issue on ServiceLoader::iterator

Ales Justin ales.justin at gmail.com
Wed May 9 11:55:38 EDT 2012


Anyone ever seen this error?

Caused by: java.util.NoSuchElementException
	at java.util.AbstractList$Itr.next(AbstractList.java:350) [classes.jar:1.6.0_31]
	at java.util.Collections$1.nextElement(Collections.java:3389) [classes.jar:1.6.0_31]
	at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:332) [classes.jar:1.6.0_31]
	at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:415) [classes.jar:1.6.0_31]
	at org.infinispan.distexec.spi.DistributedTaskLifecycleService.onPreExecute(DistributedTaskLifecycleService.java:50) [infinispan-core-5.2.0-SNAPSHOT.jar:5.2.0-SNAPSHOT]

   public <T> void onPreExecute(Callable<T> task) {
      try {
         Iterator<DistributedTaskLifecycle> i = loader.iterator();
         while (i.hasNext()) { // <------------------------------------------------- we CHECK before
            DistributedTaskLifecycle cl = i.next();
            cl.onPreExecute(task);

And I doubt I have multiple thread accessing it at the same time -- running this from serial testsuite.

I can reproduce this, atm, almost every time, where Vladimir (Blagojevic; Infinispan - author of DistributedTaskLifecycleService) cannot.

Any idea?

-Ales




More information about the jboss-development mailing list