Source:
<code>private void scheduleReloadJob(final String trigger) { if (reloadJob != null) { if (reloadJobIsInitializing) return; reloadJob.cancel(); } <START> for (Job updateJob : updateJobs) <END> updateJob.cancel(); if (!checkRepository()) return; reloadJob = new Job(getReloadJobName()) { @Override protected IStatus run(IProgressMonitor monitor) { try { reloadJobIsInitializing = true; waitForWorkspaceLock(monitor); lock.lock(); } finally { reloadJobIsInitializing = false; } if (monitor.isCanceled()) return Status.CANCEL_STATUS; try { parallelism.acquire(); long startTime = System.currentTimeMillis(); IndexDiffData result = calcIndexDiffDataFull(monitor, getName()); if (monitor.isCanceled() || (result == null)) return Status.CANCEL_STATUS; indexDiffData = result; if (GitTraceLocation.INDEXDIFFCACHE.isActive()) { long time = System.currentTimeMillis() - startTime; StringBuilder message = new StringBuilder( getTraceMessage(time)); GitTraceLocation.getTrace().trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), message.append(indexDiffData.toString()) .toString()); } notifyListeners(); return Status.OK_STATUS; } catch (IOException e) { if (GitTraceLocation.INDEXDIFFCACHE.isActive()) GitTraceLocation.getTrace().trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), "Calculating IndexDiff failed", e); return Status.OK_STATUS; } catch (InterruptedException e) { return Status.CANCEL_STATUS; } finally { lock.unlock(); parallelism.release(); } } private String getTraceMessage(long time) { return NLS .bind("\nUpdated IndexDiffData in {0} ms\nReason: {1}\nRepository: {2}\n", new Object[] { Long.valueOf(time), trigger, repository.getWorkTree().getName() }); } @Override public boolean belongsTo(Object family) { if (family.equals(JobFamilies.INDEX_DIFF_CACHE_UPDATE)) return true; return super.belongsTo(family); } }; reloadJob.schedule(); }</code><technical_language>If want this iteration thread safe need hold lock updateJobs</technical_language>

Target:
private void scheduleReloadJob(final String trigger) { if (reloadJob != null) { if (reloadJobIsInitializing) return; reloadJob.cancel(); } for (Job updateJob : updateJobs.toArray(new Job[updateJobs.size()])) updateJob.cancel(); if (!checkRepository()) return; reloadJob = new Job(getReloadJobName()) { @Override protected IStatus run(IProgressMonitor monitor) { try { reloadJobIsInitializing = true; waitForWorkspaceLock(monitor); lock.lock(); } finally { reloadJobIsInitializing = false; } try { if (monitor.isCanceled()) return Status.CANCEL_STATUS; parallelism.acquire(); long startTime = System.currentTimeMillis(); IndexDiffData result = calcIndexDiffDataFull(monitor, getName()); if (monitor.isCanceled() || (result == null)) return Status.CANCEL_STATUS; indexDiffData = result; if (GitTraceLocation.INDEXDIFFCACHE.isActive()) { long time = System.currentTimeMillis() - startTime; StringBuilder message = new StringBuilder( getTraceMessage(time)); GitTraceLocation.getTrace().trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), message.append(indexDiffData.toString()) .toString()); } notifyListeners(); return Status.OK_STATUS; } catch (IOException e) { if (GitTraceLocation.INDEXDIFFCACHE.isActive()) GitTraceLocation.getTrace().trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), "Calculating IndexDiff failed", e); return Status.OK_STATUS; } catch (InterruptedException e) { return Status.CANCEL_STATUS; } finally { lock.unlock(); parallelism.release(); } } private String getTraceMessage(long time) { return NLS .bind("\nUpdated IndexDiffData in {0} ms\nReason: {1}\nRepository: {2}\n", new Object[] { Long.valueOf(time), trigger, repository.getWorkTree().getName() }); } @Override public boolean belongsTo(Object family) { if (family.equals(JobFamilies.INDEX_DIFF_CACHE_UPDATE)) return true; return super.belongsTo(family); } }; reloadJob.schedule(); }