Skip to content

Commit 280174f

Browse files
committed
Don't use display thread for scheduling console update tasks
This fixes regression from 7e1f60c, where main thread (which owns lock on UI operations) waits for the lock on ProcessConsole to update console name but never gets it because console code is blocked internally waiting for a QueueProcessingJob being executed on UI thread. The solution is to avoid direct calls from UI to ProcessConsole.resetName(). Fixes #2460
1 parent 174da5c commit 280174f

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
import java.util.ArrayList;
3838
import java.util.Date;
3939
import java.util.List;
40+
import java.util.concurrent.Executors;
41+
import java.util.concurrent.ScheduledExecutorService;
42+
import java.util.concurrent.ScheduledFuture;
43+
import java.util.concurrent.TimeUnit;
4044
import java.util.regex.Pattern;
4145

4246
import org.eclipse.core.resources.IFile;
@@ -140,6 +144,8 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe
140144
private volatile boolean fStreamsClosed;
141145
private volatile boolean disposed;
142146

147+
private final ScheduledExecutorService consoleNameUpdateExecutor;
148+
private volatile ScheduledFuture<?> pendingNameUpdate;
143149

144150
/**
145151
* Create process console with default encoding.
@@ -164,6 +170,11 @@ public ProcessConsole(IProcess process, IConsoleColorProvider colorProvider, Str
164170
fAllocateConsole = true;
165171
fProcess = process;
166172
fUserInput = getInputStream();
173+
consoleNameUpdateExecutor = Executors.newSingleThreadScheduledExecutor(r -> {
174+
Thread t = new Thread(r, "Console name updater"); //$NON-NLS-1$
175+
t.setDaemon(true);
176+
return t;
177+
});
167178

168179
ILaunchConfiguration configuration = process.getLaunch().getLaunchConfiguration();
169180
String file = null;
@@ -401,13 +412,18 @@ private void triggerAsyncConsoleNameUpdate() {
401412
if (disposed) {
402413
return;
403414
}
404-
DebugUIPlugin.getStandardDisplay().asyncExec(() -> {
405-
if (disposed) {
406-
return;
407-
}
408-
// refresh every second:
409-
DebugUIPlugin.getStandardDisplay().timerExec(1000, () -> resetName(false));
410-
});
415+
416+
// refresh every second, but only if not already scheduled:
417+
ScheduledFuture<?> currentPending = pendingNameUpdate;
418+
if (currentPending == null || currentPending.isDone()) {
419+
currentPending = consoleNameUpdateExecutor.schedule(() -> {
420+
pendingNameUpdate = null;
421+
if (disposed) {
422+
return;
423+
}
424+
resetName(false);
425+
}, 1, TimeUnit.SECONDS);
426+
}
411427
}
412428

413429
private static String computeElapsedTimeLabel(Date launchTime, Date terminateTime) {
@@ -550,6 +566,7 @@ public IProcess getProcess() {
550566
@Override
551567
protected void dispose() {
552568
super.dispose();
569+
consoleNameUpdateExecutor.shutdownNow();
553570
fColorProvider.disconnect();
554571
DebugPlugin.getDefault().removeDebugEventListener(this);
555572
DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);

0 commit comments

Comments
 (0)