diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java index 4adc5cb083a..db2a5dd6bb3 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java +++ b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java @@ -14,6 +14,7 @@ * Michael Scharf (Wind River) - split into core, view and connector plugins * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - [206892] State handling: Only allow connect when CLOSED + * Martin Oberhuber (Wind River) - [206883] Serial Terminal leaks Jobs *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -107,6 +108,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC private final ITerminalTextData fTerminalModel; + /** + * Is protected by synchronize on this + */ volatile private Job fJob; public VT100TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnectorInfo[] connectors) { @@ -288,7 +292,22 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC if(getTerminalConnector()!=null) { getTerminalConnector().disconnect(); } - } + //Ensure that a new Job can be started; then clean up old Job. + //TODO not sure whether the fInputStream needs to be cleaned too, + //or whether the Job could actually cancel in case the fInputStream is closed. + Job job; + synchronized(this) { + job = fJob; + fJob = null; + } + if (job!=null) { + job.cancel(); + //There's not really a need to interrupt, since the job will + //check its cancel status after 500 msec latest anyways... + //Thread t = job.getThread(); + //if(t!=null) t.interrupt(); + } + } // TODO private void waitForConnect() { @@ -313,7 +332,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC } - private void startReaderJob() { + private synchronized void startReaderJob() { if(fJob==null) { fJob=new Job("Terminal data reader") { //$NON-NLS-1$ protected IStatus run(IProgressMonitor monitor) {