Skip to content

Commit

Permalink
Prevent JobManager UI freeze when waiting for a rule in the UI Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed May 1, 2022
1 parent 6dc15f1 commit 86d3c47
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2020 IBM Corporation and others.
* Copyright (c) 2003, 2022 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,7 @@
* - Fix for Bug 151204 [Progress] Blocked status of jobs are not applied/reported
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 422040
* Philipp Bumann <bumannp@gmail.com> - Bug 477602
* Christoph Läubrich - Issue #8
*******************************************************************************/
package org.eclipse.e4.ui.progress.internal;

Expand All @@ -35,7 +36,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
Expand Down Expand Up @@ -511,16 +511,21 @@ protected void sleepJobInfo(JobInfo info) {

@Override
public IProgressMonitor getDefaultMonitor() {
return monitorFor(null);
}

@Override
public IProgressMonitor monitorFor(IProgressMonitor monitor) {
// only need a default monitor for operations the UI thread
// and only if there is a display
Display display;
if (PlatformUI.isWorkbenchRunning() && !PlatformUI.isWorkbenchStarting()) {
display = getDisplay();
if (!display.isDisposed() && (display.getThread() == Thread.currentThread())) {
return new EventLoopProgressMonitor(new NullProgressMonitor());
return new EventLoopProgressMonitor(IProgressMonitor.nullSafe(monitor));
}
}
return super.getDefaultMonitor();
return IProgressMonitor.nullSafe(monitor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2020 IBM Corporation and others.
* Copyright (c) 2003, 2022 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,7 @@
* - Fix for Bug 151204 [Progress] Blocked status of jobs are not applied/reported
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 422040
* Terry Parker - Bug 454633, Report the cumulative error status of job groups in the ProgressManager
* Christoph Läubrich - Issue #8
*******************************************************************************/
package org.eclipse.ui.internal.progress;

Expand Down Expand Up @@ -575,16 +576,21 @@ public IProgressMonitor createMonitor(Job job) {

@Override
public IProgressMonitor getDefaultMonitor() {
return monitorFor(null);
}

@Override
public IProgressMonitor monitorFor(IProgressMonitor monitor) {
// only need a default monitor for operations the UI thread
// and only if there is a display
Display display;
if (PlatformUI.isWorkbenchRunning() && !PlatformUI.getWorkbench().isStarting()) {
display = PlatformUI.getWorkbench().getDisplay();
if (!display.isDisposed() && (display.getThread() == Thread.currentThread())) {
return new EventLoopProgressMonitor(new NullProgressMonitor());
return new EventLoopProgressMonitor(IProgressMonitor.nullSafe(monitor));
}
}
return super.getDefaultMonitor();
return IProgressMonitor.nullSafe(monitor);
}

/**
Expand Down
1 change: 1 addition & 0 deletions bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.19.0,4.0.0)",
org.eclipse.core.databinding.property;bundle-version="[1.2.0,2.0.0)",
org.eclipse.core.databinding.observable;bundle-version="[1.2.0,2.0.0)",
org.eclipse.core.expressions;bundle-version="[3.7.0,4.0.0)",
org.eclipse.core.jobs;bundle-version="[3.13.0,4.0.0)",
org.eclipse.e4.core.services;bundle-version="2.2.0",
org.eclipse.e4.core.contexts;bundle-version="1.0.0",
org.eclipse.e4.core.di;bundle-version="1.1.0",
Expand Down

0 comments on commit 86d3c47

Please sign in to comment.