Skip to content

Commit

Permalink
* 确保 子进程、子流程关闭
Browse files Browse the repository at this point in the history
  • Loading branch information
fjn committed Feb 7, 2021
1 parent 7ec6c5f commit 70dd7e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.jn.langx.util.concurrent.completion.CompletableFuture;
import com.jn.langx.util.function.Function;
import com.jn.langx.util.function.Supplier0;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -36,6 +38,7 @@
* </pre>
*/
public class DefaultCommandLineExecutor implements CommandLineExecutor {
private Logger logger = LoggerFactory.getLogger(DefaultCommandLineExecutor.class);
private ExecutorService executorService;
/**
* taking care of output and error stream
Expand Down Expand Up @@ -423,7 +426,24 @@ protected int executeInternal(final CommandLine command, final Map<String, Strin
} finally {
// remove the process to the list of those to destroy if the VM exits
if (this.getProcessDestroyer() != null) {
this.getProcessDestroyer().remove(process);
try {
this.getProcessDestroyer().remove(process);
} catch (Throwable ex) {
logger.error(ex.getMessage(), ex);
}
}
if (this.watchdog != null) {
try {
this.watchdog.stop();
} catch (Throwable ex) {
logger.error(ex.getMessage(), ex);
}
} else {
try {
process.destroy();
} catch (Throwable ex) {
logger.error(ex.getMessage(), ex);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onProcessFailed(final ExecuteException e) {
public ExecuteException getException() {

if (!hasResult) {
throw new IllegalStateException("The process has not exited yet therefore no result is available ...");
throw new IllegalStateException("The instruction sequence has not exited yet therefore no result is available ...");
}

return exception;
Expand All @@ -76,7 +76,7 @@ public ExecuteException getException() {
public int getExitValue() {

if (!hasResult) {
throw new IllegalStateException("The process has not exited yet therefore no result is available ...");
throw new IllegalStateException("The instruction sequence has not exited yet therefore no result is available ...");
}

return exitValue;
Expand Down

0 comments on commit 70dd7e7

Please sign in to comment.