fixed a silly thread blocking problem

This commit is contained in:
hypercubus
2004-08-21 11:01:12 +00:00
committed by zzz
parent 3c772f1974
commit 921aef7f2c
2 changed files with 29 additions and 7 deletions

View File

@@ -17,7 +17,8 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
/** /**
* Passes a command to the OS shell for execution and manages the output. * Passes a command to the OS shell for execution and manages the input and
* output.
* <p> * <p>
* This class must be kept <code>gcj</code>-compatible. * This class must be kept <code>gcj</code>-compatible.
* *
@@ -35,6 +36,7 @@ public class ShellCommand {
private CommandThread _commandThread; private CommandThread _commandThread;
private InputStream _errorStream; private InputStream _errorStream;
private InputStream _inputStream; private InputStream _inputStream;
private boolean _isTimerRunning;
private OutputStream _outputStream; private OutputStream _outputStream;
private Process _process; private Process _process;
@@ -45,11 +47,11 @@ public class ShellCommand {
*/ */
private class CommandThread extends Thread { private class CommandThread extends Thread {
Object caller; Thread caller;
boolean consumeOutput; boolean consumeOutput;
String shellCommand; String shellCommand;
CommandThread(Object caller, String shellCommand, boolean consumeOutput) { CommandThread(Thread caller, String shellCommand, boolean consumeOutput) {
super("CommandThread"); super("CommandThread");
this.caller = caller; this.caller = caller;
this.shellCommand = shellCommand; this.shellCommand = shellCommand;
@@ -58,8 +60,10 @@ public class ShellCommand {
public void run() { public void run() {
_commandSuccessful = execute(shellCommand, consumeOutput, WAIT_FOR_EXIT_STATUS); _commandSuccessful = execute(shellCommand, consumeOutput, WAIT_FOR_EXIT_STATUS);
synchronized(caller) { if (_isTimerRunning) {
caller.notify(); // In case the caller is still in the wait() state. synchronized(caller) {
caller.interrupt(); // In case the caller is still in the wait() state.
}
} }
} }
} }
@@ -236,13 +240,16 @@ public class ShellCommand {
try { try {
if (seconds > 0) { if (seconds > 0) {
_isTimerRunning = true;
wait(seconds * 1000); wait(seconds * 1000);
_isTimerRunning = false;
return true; return true;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Wake up, time to die. // Wake up, time to die.
} }
_isTimerRunning = false;
if (_commandSuccessful) if (_commandSuccessful)
return true; return true;
@@ -302,13 +309,16 @@ public class ShellCommand {
try { try {
if (seconds > 0) { if (seconds > 0) {
_isTimerRunning = true;
wait(seconds * 1000); wait(seconds * 1000);
_isTimerRunning = false;
return true; return true;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Wake up, time to die. // Wake up, time to die.
} }
_isTimerRunning = false;
if (_commandSuccessful) if (_commandSuccessful)
return true; return true;

View File

@@ -51,6 +51,9 @@ public class SysTray implements SysTrayMenuListener {
public void iconLeftClicked(SysTrayMenuEvent e) {} public void iconLeftClicked(SysTrayMenuEvent e) {}
public void iconLeftDoubleClicked(SysTrayMenuEvent e) { public void iconLeftDoubleClicked(SysTrayMenuEvent e) {
String browser = null;
if (_browserString == null || _browserString.equals("default")) { if (_browserString == null || _browserString.equals("default")) {
try { try {
@@ -70,7 +73,10 @@ public class SysTray implements SysTrayMenuListener {
// Fall through. // Fall through.
} }
} }
setBrowser(promptForBrowser("Please select another browser"));
if ((browser = promptForBrowser("Please select another browser")) != null)
setBrowser(browser);
} }
public void menuItemSelected(SysTrayMenuEvent e) { public void menuItemSelected(SysTrayMenuEvent e) {
@@ -98,9 +104,15 @@ public class SysTray implements SysTrayMenuListener {
} }
private String promptForBrowser(String windowTitle) { private String promptForBrowser(String windowTitle) {
String browser = null;
_frame = new Frame(); _frame = new Frame();
_browserChooser = new BrowserChooser(_frame, windowTitle); _browserChooser = new BrowserChooser(_frame, windowTitle);
return _browserChooser.getDirectory() + _browserChooser.getFile(); browser = _browserChooser.getDirectory() + _browserChooser.getFile();
_browserChooser = null;
_frame = null;
return browser;
} }
private void setBrowser(String browser) { private void setBrowser(String browser) {