View | Details | Raw Unified | Return to bug 395645
Collapse All | Expand All

(-)a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressViewUpdater.java (-52 / +74 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2009 IBM Corporation and others.
2
 * Copyright (c) 2003, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-19 package org.eclipse.ui.internal.progress; Link Here
13
import java.util.Collection;
13
import java.util.Collection;
14
import java.util.HashSet;
14
import java.util.HashSet;
15
import java.util.Iterator;
15
import java.util.Iterator;
16
17
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.Status;
Lines 38-43 class ProgressViewUpdater implements IJobProgressManagerListener { Link Here
38
37
39
    Object updateLock = new Object();
38
    Object updateLock = new Object();
40
39
40
	class MutableBoolean {
41
		boolean value;
42
	}
43
44
	/*
45
	 * True when update job is scheduled or running. This is used to limit the
46
	 * update job to no more than once every 100 ms.
47
	 */
48
	MutableBoolean updateScheduled = new MutableBoolean();
49
41
    boolean debug;
50
    boolean debug;
42
    
51
    
43
   
52
   
Lines 217-236 class ProgressViewUpdater implements IJobProgressManagerListener { Link Here
217
		}
226
		}
218
    }
227
    }
219
228
220
    /** keep track of how often we schedule the job to avoid overloading the JobManager */
221
    private long lastUpdateJobScheduleRequest = 0;
222
    
223
    /**
229
    /**
224
     * Schedule an update.
230
     * Schedule an update.
225
     */
231
     */
226
    void scheduleUpdate() {
232
    void scheduleUpdate() {
227
        if (PlatformUI.isWorkbenchRunning()) {
233
        if (PlatformUI.isWorkbenchRunning()) {
228
            // make sure we don't schedule too often
234
            // make sure we don't schedule too often
229
        	long now = System.currentTimeMillis();
235
			synchronized (updateScheduled) {
230
        	if (now - lastUpdateJobScheduleRequest >= 100) {
236
				if (!updateScheduled.value) {
231
        		//Add in a 100ms delay so as to keep priority low
237
					updateScheduled.value = true;
232
        		updateJob.schedule(100);
238
					updateJob.schedule(100);
233
        		lastUpdateJobScheduleRequest = now;
239
				}
234
        	}
240
        	}
235
        }
241
        }
236
    }
242
    }
Lines 246-296 class ProgressViewUpdater implements IJobProgressManagerListener { Link Here
246
             * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
252
             * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
247
             */
253
             */
248
            public IStatus runInUIThread(IProgressMonitor monitor) {
254
            public IStatus runInUIThread(IProgressMonitor monitor) {
249
255
				synchronized (updateScheduled) {
250
                //Abort the job if there isn't anything
256
					try {
251
                if (collectors.length == 0) {
257
						// Abort the job if there isn't anything
252
					return Status.CANCEL_STATUS;
258
						if (collectors.length == 0) {
253
				}
259
							return Status.CANCEL_STATUS;
254
255
                if (currentInfo.updateAll) {
256
                    synchronized (updateLock) {
257
                        currentInfo.reset();
258
                    }
259
                    for (int i = 0; i < collectors.length; i++) {
260
                        collectors[i].refresh();
261
                    }
262
263
                } else {
264
                    //Lock while getting local copies of the caches.
265
                    Object[] updateItems;
266
                    Object[] additionItems;
267
                    Object[] deletionItems;
268
                    synchronized (updateLock) {
269
                        currentInfo.processForUpdate();
270
271
                        updateItems = currentInfo.refreshes.toArray();
272
                        additionItems = currentInfo.additions.toArray();
273
                        deletionItems = currentInfo.deletions.toArray();
274
275
                        currentInfo.reset();
276
                    }
277
278
                    for (int v = 0; v < collectors.length; v++) {
279
                        IProgressUpdateCollector collector = collectors[v];
280
281
                        if (updateItems.length > 0) {
282
							collector.refresh(updateItems);
283
						}
260
						}
284
                        if (additionItems.length > 0) {
261
285
							collector.add(additionItems);
262
						if (currentInfo.updateAll) {
286
						}
263
							synchronized (updateLock) {
287
                        if (deletionItems.length > 0) {
264
								currentInfo.reset();
288
							collector.remove(deletionItems);
265
							}
266
							for (int i = 0; i < collectors.length; i++) {
267
								collectors[i].refresh();
268
							}
269
270
						} else {
271
							// Lock while getting local copies of the caches.
272
							Object[] updateItems;
273
							Object[] additionItems;
274
							Object[] deletionItems;
275
							synchronized (updateLock) {
276
								currentInfo.processForUpdate();
277
278
								updateItems = currentInfo.refreshes.toArray();
279
								additionItems = currentInfo.additions.toArray();
280
								deletionItems = currentInfo.deletions.toArray();
281
282
								currentInfo.reset();
283
							}
284
285
							for (int v = 0; v < collectors.length; v++) {
286
								IProgressUpdateCollector collector = collectors[v];
287
288
								if (updateItems.length > 0) {
289
									collector.refresh(updateItems);
290
								}
291
								if (additionItems.length > 0) {
292
									collector.add(additionItems);
293
								}
294
								if (deletionItems.length > 0) {
295
									collector.remove(deletionItems);
296
								}
297
							}
289
						}
298
						}
290
                    }
291
                }
292
299
293
                return Status.OK_STATUS;
300
						return Status.OK_STATUS;
301
					} finally {
302
						updateScheduled.value = false;
303
					}
304
				}
305
			}
306
307
			/*
308
			 * (non-Javadoc)
309
			 * 
310
			 * @see org.eclipse.core.runtime.jobs.Job#canceling()
311
			 */
312
			protected void canceling() {
313
				synchronized (updateScheduled) {
314
					updateScheduled.value = false;
315
				}
294
            }
316
            }
295
        };
317
        };
296
        updateJob.setSystem(true);
318
        updateJob.setSystem(true);

Return to bug 395645