Search in sources :

Example 1 with ThreadReader

use of org.ow2.proactive.scheduler.task.utils.ThreadReader in project scheduling by ow2-proactive.

the class JavaSpawnExecutable method execute.

@Override
public Serializable execute(TaskResult... results) throws Throwable {
    org.apache.log4j.Logger.getLogger(ProcessTree.class).setLevel(Level.DEBUG);
    Process process = null;
    process = Runtime.getRuntime().exec(getNativeExecLauncher(false), null, getExecutablePath(launchersDir).getParentFile().getCanonicalFile());
    // redirect streams
    BufferedReader sout = new BufferedReader(new InputStreamReader(process.getInputStream()));
    BufferedReader serr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    Thread tsout = new Thread(new ThreadReader(sout, System.out));
    Thread tserr = new Thread(new ThreadReader(serr, System.err));
    tsout.setDaemon(true);
    tserr.setDaemon(true);
    tsout.start();
    tserr.start();
    process.waitFor();
    // we sleep 2 sec
    Thread.sleep(sleep * 1000);
    return true;
}
Also used : InputStreamReader(java.io.InputStreamReader) ProcessTree(org.ow2.proactive.process_tree_killer.ProcessTree) BufferedReader(java.io.BufferedReader) ThreadReader(org.ow2.proactive.scheduler.task.utils.ThreadReader)

Aggregations

BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ProcessTree (org.ow2.proactive.process_tree_killer.ProcessTree)1 ThreadReader (org.ow2.proactive.scheduler.task.utils.ThreadReader)1