Source:
public void execute(Job job, String token) throws Exception { Runnable runnable = () -> { try { ExecutorConfig executorConfig = ExecutorConfig.getExecutorConfig(job); logger.info("Ready to run {}", job.getCommandLine()); Command com = new Command(job.getCommandLine() + " --session-id " + token); DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream(executorConfig.getStdout())); com.setOutputOutputStream(dataOutputStream); dataOutputStream = new DataOutputStream(new FileOutputStream(executorConfig.getStderr())); com.setErrorOutputStream(dataOutputStream); final long jobId = job.getUid(); Thread hook = new Thread(() -> { logger.info("Running ShutdownHook. Job {id: " + jobId + "} has being aborted."); com.setStatus(RunnableProcess.Status.KILLED); com.setExitValue(-2); closeOutputStreams(com); }); logger.info("=========================================="); logger.info("Executing job {}({})", job.getName(), job.getUid()); logger.debug("Executing commandLine {}", job.getCommandLine()); logger.info("=========================================="); System.err.println(); Runtime.getRuntime().addShutdownHook(hook); com.run(); Runtime.getRuntime().removeShutdownHook(hook); System.err.println(); logger.info("=========================================="); logger.info("Finished job {}({})", job.getName(), job.getUid()); logger.info("=========================================="); closeOutputStreams(com); } catch (FileNotFoundException e) { logger.error("Could not create the output/error files", e); } }; Thread thread = new Thread(runnable, "LocalExecutor-" + nextThreadNum()); thread.start(); }

Target:
public void execute(Job job, String token) throws Exception { Runnable runnable = () -> { try { ExecutorConfig executorConfig = ExecutorConfig.getExecutorConfig(job); logger.info("Ready to run {}", job.getCommandLine()); Command com = new Command(getCommandLine(job, token)); DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream(executorConfig.getStdout())); com.setOutputOutputStream(dataOutputStream); dataOutputStream = new DataOutputStream(new FileOutputStream(executorConfig.getStderr())); com.setErrorOutputStream(dataOutputStream); final long jobId = job.getUid(); Thread hook = new Thread(() -> { logger.info("Running ShutdownHook. Job {id: " + jobId + "} has being aborted."); com.setStatus(RunnableProcess.Status.KILLED); com.setExitValue(-2); closeOutputStreams(com); }); logger.info("=========================================="); logger.info("Executing job {}({})", job.getName(), job.getUid()); logger.debug("Executing commandLine {}", job.getCommandLine()); logger.info("=========================================="); System.err.println(); Runtime.getRuntime().addShutdownHook(hook); com.run(); Runtime.getRuntime().removeShutdownHook(hook); System.err.println(); logger.info("=========================================="); logger.info("Finished job {}({})", job.getName(), job.getUid()); logger.info("=========================================="); closeOutputStreams(com); } catch (FileNotFoundException e) { logger.error("Could not create the output/error files", e); } }; Thread thread = new Thread(runnable, "LocalExecutor-" + nextThreadNum()); thread.start(); }