Package au.edu.mq.comp.common.concurrency

Examples of au.edu.mq.comp.common.concurrency.StreamReader


        //System.out.println("going to run java class with command -->" + command);
        //System.out.println("current working dir for command is -->" + this.pathToClass);
        java.lang.Process p = pb.start();
       
        int exitCode = -1;
        StreamReader outputStreamReader = new StreamReader(p.getInputStream());
        StreamReader errorStreamReader = new StreamReader(p.getErrorStream());
        outputStreamReader.start();
        errorStreamReader.start();
        if(timeOutInMillisec > 0)
        {
            Timer timer = null;
            try
            {
                timer = new Timer(true);
                InterruptTimerTask interrupter = new InterruptTimerTask(Thread.currentThread());
                timer.schedule(interrupter, timeOutInMillisec);
                exitCode = p.waitFor();
            }
            catch(InterruptedException e)
            {
                // do something to handle the timeout here
                Log.message("going to kill process with hashcode " + p.hashCode());
                p.destroy();
                exitCode = JavaClassRunner.kWaitForProcessTimeout;
                Log.message("process with hashcode " + p.hashCode() + " killed");
            }
            finally
            {
                timer.cancel();
                Thread.interrupted();
            }
        }
        else
        {
            exitCode = p.waitFor();
        }
        this.outputString = outputStreamReader.toString();
        this.errorString = errorStreamReader.toString();
        return exitCode;
    }
View Full Code Here

TOP

Related Classes of au.edu.mq.comp.common.concurrency.StreamReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.