forked from I2P_Developers/i2p.i2p
synchronized on (and .wait/notify against) the ShellCommand, not the Thread.
in general the old way worked often, but would sometimes cause a race, this should be a bit safer
This commit is contained in:
@ -48,11 +48,11 @@ public class ShellCommand {
|
|||||||
*/
|
*/
|
||||||
private class CommandThread extends Thread {
|
private class CommandThread extends Thread {
|
||||||
|
|
||||||
Thread caller;
|
Object caller;
|
||||||
boolean consumeOutput;
|
boolean consumeOutput;
|
||||||
String shellCommand;
|
String shellCommand;
|
||||||
|
|
||||||
CommandThread(Thread caller, String shellCommand, boolean consumeOutput) {
|
CommandThread(Object caller, String shellCommand, boolean consumeOutput) {
|
||||||
super("CommandThread");
|
super("CommandThread");
|
||||||
this.caller = caller;
|
this.caller = caller;
|
||||||
this.shellCommand = shellCommand;
|
this.shellCommand = shellCommand;
|
||||||
@ -63,7 +63,7 @@ public class ShellCommand {
|
|||||||
_commandSuccessful = execute(shellCommand, consumeOutput, WAIT_FOR_EXIT_STATUS);
|
_commandSuccessful = execute(shellCommand, consumeOutput, WAIT_FOR_EXIT_STATUS);
|
||||||
if (_isTimerRunning) {
|
if (_isTimerRunning) {
|
||||||
synchronized(caller) {
|
synchronized(caller) {
|
||||||
caller.interrupt(); // In case the caller is still in the wait() state.
|
caller.notifyAll(); // In case the caller is still in the wait() state.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ public class ShellCommand {
|
|||||||
*/
|
*/
|
||||||
public synchronized boolean executeAndWaitTimed(String shellCommand, int seconds) {
|
public synchronized boolean executeAndWaitTimed(String shellCommand, int seconds) {
|
||||||
|
|
||||||
_commandThread = new CommandThread(Thread.currentThread(), shellCommand, NO_CONSUME_OUTPUT);
|
_commandThread = new CommandThread(this, shellCommand, NO_CONSUME_OUTPUT);
|
||||||
_commandThread.start();
|
_commandThread.start();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ public class ShellCommand {
|
|||||||
*/
|
*/
|
||||||
public synchronized boolean executeSilentAndWaitTimed(String shellCommand, int seconds) {
|
public synchronized boolean executeSilentAndWaitTimed(String shellCommand, int seconds) {
|
||||||
|
|
||||||
_commandThread = new CommandThread(Thread.currentThread(), shellCommand, CONSUME_OUTPUT);
|
_commandThread = new CommandThread(this, shellCommand, CONSUME_OUTPUT);
|
||||||
_commandThread.start();
|
_commandThread.start();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user