summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-07-03 18:15:47 +0200
committerSimon Rettberg2023-07-03 18:15:47 +0200
commit99c04872cddb2b9eb537174ed96e49989b2aa162 (patch)
tree0c70e3e6451f0d42560d13a1a0302748fab5cf41
parentAdd tmcli, very simple CLI tool (diff)
downloadtaskman-lite-99c04872cddb2b9eb537174ed96e49989b2aa162.tar.gz
taskman-lite-99c04872cddb2b9eb537174ed96e49989b2aa162.tar.xz
taskman-lite-99c04872cddb2b9eb537174ed96e49989b2aa162.zip
Simplify timed wait in SystemCommandTask
-rw-r--r--api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java29
1 files changed, 12 insertions, 17 deletions
diff --git a/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java b/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java
index 172d2ed..4754dca 100644
--- a/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java
+++ b/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java
@@ -7,6 +7,7 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -40,8 +41,8 @@ public abstract class SystemCommandTask extends AbstractTask
if ( command == null || command.length == 0 ) {
return processEnded( -1 );
}
- for (String a : command) {
- if (a == null) {
+ for ( String a : command ) {
+ if ( a == null ) {
log.warn( "An argument from initCommandLine is null: " + Arrays.toString( command ) );
return processEnded( -5 );
}
@@ -110,23 +111,15 @@ public abstract class SystemCommandTask extends AbstractTask
// Wait for everything
int retval = 124; // Default to 124, which is what the timeout util does
- if ( this.timeoutSeconds <= 0 ) {
- retval = process.waitFor();
- } else {
- int togo = timeoutSeconds * 10;
- while ( togo-- > 0 ) {
- try {
+ try {
+ if ( this.timeoutSeconds <= 0 ) {
+ retval = process.waitFor();
+ } else {
+ if ( process.waitFor( this.timeoutSeconds, TimeUnit.SECONDS ) ) {
retval = process.exitValue();
- break;
- } catch ( IllegalThreadStateException e1 ) {
- // Still running....
- try {
- Thread.sleep( 100 );
- } catch ( Exception e2 ) {
- // Bummer....
- }
}
}
+ } catch ( IllegalThreadStateException e1 ) {
}
try {
stdout.join( 500 );
@@ -155,8 +148,9 @@ public abstract class SystemCommandTask extends AbstractTask
Thread.currentThread().interrupt();
return false;
} finally {
- if ( process != null )
+ if ( process != null ) {
process.destroy();
+ }
}
}
@@ -217,6 +211,7 @@ public abstract class SystemCommandTask extends AbstractTask
/**
* Override this to modify the environment of the process to be started.
+ *
* @param environment
*/
protected void initEnvironment( Map<String, String> environment )