diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressViewUpdater.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressViewUpdater.java index 33946a9..3fd3935 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressViewUpdater.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressViewUpdater.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2009 IBM Corporation and others. + * Copyright (c) 2003, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,7 +13,6 @@ package org.eclipse.ui.internal.progress; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; - import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -38,6 +37,16 @@ class ProgressViewUpdater implements IJobProgressManagerListener { Object updateLock = new Object(); + class MutableBoolean { + boolean value; + } + + /* + * True when update job is scheduled or running. This is used to limit the + * update job to no more than once every 100 ms. + */ + MutableBoolean updateScheduled = new MutableBoolean(); + boolean debug; @@ -217,20 +226,17 @@ class ProgressViewUpdater implements IJobProgressManagerListener { } } - /** keep track of how often we schedule the job to avoid overloading the JobManager */ - private long lastUpdateJobScheduleRequest = 0; - /** * Schedule an update. */ void scheduleUpdate() { if (PlatformUI.isWorkbenchRunning()) { // make sure we don't schedule too often - long now = System.currentTimeMillis(); - if (now - lastUpdateJobScheduleRequest >= 100) { - //Add in a 100ms delay so as to keep priority low - updateJob.schedule(100); - lastUpdateJobScheduleRequest = now; + synchronized (updateScheduled) { + if (!updateScheduled.value) { + updateScheduled.value = true; + updateJob.schedule(100); + } } } } @@ -246,51 +252,67 @@ class ProgressViewUpdater implements IJobProgressManagerListener { * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) */ public IStatus runInUIThread(IProgressMonitor monitor) { - - //Abort the job if there isn't anything - if (collectors.length == 0) { - return Status.CANCEL_STATUS; - } - - if (currentInfo.updateAll) { - synchronized (updateLock) { - currentInfo.reset(); - } - for (int i = 0; i < collectors.length; i++) { - collectors[i].refresh(); - } - - } else { - //Lock while getting local copies of the caches. - Object[] updateItems; - Object[] additionItems; - Object[] deletionItems; - synchronized (updateLock) { - currentInfo.processForUpdate(); - - updateItems = currentInfo.refreshes.toArray(); - additionItems = currentInfo.additions.toArray(); - deletionItems = currentInfo.deletions.toArray(); - - currentInfo.reset(); - } - - for (int v = 0; v < collectors.length; v++) { - IProgressUpdateCollector collector = collectors[v]; - - if (updateItems.length > 0) { - collector.refresh(updateItems); + synchronized (updateScheduled) { + try { + // Abort the job if there isn't anything + if (collectors.length == 0) { + return Status.CANCEL_STATUS; } - if (additionItems.length > 0) { - collector.add(additionItems); - } - if (deletionItems.length > 0) { - collector.remove(deletionItems); + + if (currentInfo.updateAll) { + synchronized (updateLock) { + currentInfo.reset(); + } + for (int i = 0; i < collectors.length; i++) { + collectors[i].refresh(); + } + + } else { + // Lock while getting local copies of the caches. + Object[] updateItems; + Object[] additionItems; + Object[] deletionItems; + synchronized (updateLock) { + currentInfo.processForUpdate(); + + updateItems = currentInfo.refreshes.toArray(); + additionItems = currentInfo.additions.toArray(); + deletionItems = currentInfo.deletions.toArray(); + + currentInfo.reset(); + } + + for (int v = 0; v < collectors.length; v++) { + IProgressUpdateCollector collector = collectors[v]; + + if (updateItems.length > 0) { + collector.refresh(updateItems); + } + if (additionItems.length > 0) { + collector.add(additionItems); + } + if (deletionItems.length > 0) { + collector.remove(deletionItems); + } + } } - } - } - return Status.OK_STATUS; + return Status.OK_STATUS; + } finally { + updateScheduled.value = false; + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.jobs.Job#canceling() + */ + protected void canceling() { + synchronized (updateScheduled) { + updateScheduled.value = false; + } } }; updateJob.setSystem(true);