Skip to content

Commit d86b605

Browse files
committed
SwingConsolePane: update console only on the EDT
This avoids serious issues with multithreaded output, as seen in TrakEM2 and reported by Stephen Saalfeld. Unfortunately, there are substantial performance ramifications. We may need to batch up the output into a queue, to minimize the number of Runnables that get spawn and queued.
1 parent 1295208 commit d86b605

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/main/java/org/scijava/ui/swing/console/SwingConsolePane.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,21 @@ public void setWindow(final Component window) {
9898
@Override
9999
public void append(final OutputEvent event) {
100100
if (consolePanel == null) initConsolePanel();
101-
final boolean atBottom = StaticSwingUtils.isScrolledToBottom(scrollPane);
102-
try {
103-
doc.insertString(doc.getLength(), event.getOutput(), getStyle(event));
104-
}
105-
catch (final BadLocationException exc) {
106-
throw new RuntimeException(exc);
107-
}
108-
if (atBottom) StaticSwingUtils.scrollToBottom(scrollPane);
101+
threadService.queue(new Runnable() {
102+
103+
@Override
104+
public void run() {
105+
final boolean atBottom =
106+
StaticSwingUtils.isScrolledToBottom(scrollPane);
107+
try {
108+
doc.insertString(doc.getLength(), event.getOutput(), getStyle(event));
109+
}
110+
catch (final BadLocationException exc) {
111+
throw new RuntimeException(exc);
112+
}
113+
if (atBottom) StaticSwingUtils.scrollToBottom(scrollPane);
114+
}
115+
});
109116
}
110117

111118
@Override

0 commit comments

Comments
 (0)