- int offset = 0;
- for (ListenableFuture<Void> future : futures) {
- try {
- future.get(0, TimeUnit.NANOSECONDS);
- } catch (final TimeoutException e) {
- LOG.warn("Future #{}/{} not completed yet", offset, size);
- } catch (final ExecutionException e) {
- LOG.warn("Future #{}/{} failed", offset, size, e.getCause());
- } catch (final InterruptedException e) {
- LOG.warn("Interrupted while examining future #{}/{}", offset, size, e);
+ // Guards iteration against concurrent modification from callbacks
+ synchronized (futures) {
+ int offset = 0;
+
+ for (ListenableFuture<?> future : futures) {
+ try {
+ future.get(0, TimeUnit.NANOSECONDS);
+ } catch (final TimeoutException e) {
+ LOG.warn("Future #{}/{} not completed yet", offset, size);
+ } catch (final ExecutionException e) {
+ LOG.warn("Future #{}/{} failed", offset, size, e.getCause());
+ } catch (final InterruptedException e) {
+ LOG.warn("Interrupted while examining future #{}/{}", offset, size, e);
+ }
+
+ ++offset;