@Deprecated
public class TimeLimitProcess
extends java.lang.Process
ProcessBuilder pb = ...; TimeLimitProcess p = new TimeLimitProcess(pb.start(), TIMEOUT_SEC * 1000);Note: If a Java process is destroyed (e.g., because it times out), then its output is unreadable: Java code trying to read its output stream fails. Here are two ways to get around this problem:
Constructor and Description |
---|
TimeLimitProcess(java.lang.Process p,
long timeLimit)
Deprecated.
Creates a TimeLimitProcess with the given time limit, in wall clock milliseconds.
|
TimeLimitProcess(java.lang.Process p,
long timeLimit,
boolean cacheStdout)
Deprecated.
Creates a TimeLimitProcess with the given time limit, in wall clock milliseconds.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Deprecated.
Kills the subprocess.
|
int |
exitValue()
Deprecated.
Return the exit value for the subprocess.
|
boolean |
finished()
Deprecated.
|
java.io.InputStream |
getErrorStream()
Deprecated.
Gets the error stream connected to the error output of the subprocess.
|
java.io.InputStream |
getInputStream()
Deprecated.
Gets an input stream connected to the output of the subprocess.
|
java.io.OutputStream |
getOutputStream()
Deprecated.
Gets the output stream connected to the input of the subprocess.
|
boolean |
timed_out()
Deprecated.
Returns true if the process has timed out (has run for more than the timeLimit msecs specified
in the constructor).
|
long |
timeout_msecs()
Deprecated.
Return the timeout time in msecs.
|
int |
waitFor()
Deprecated.
Causes the current thread to wait, if necessary, until the process represented by this Process
object has terminated.
|
public TimeLimitProcess(java.lang.Process p, long timeLimit)
p
- non-null Process to limit the execution oftimeLimit
- in millisecondspublic TimeLimitProcess(java.lang.Process p, long timeLimit, boolean cacheStdout)
p
- non-null Process to limit the execution oftimeLimit
- in millisecondscacheStdout
- if true, causes the TimeLimitProcess to consume the standard output of the
underlying process, and to cache it. After the process terminates (on its own or by being
timed out), the output is available via the cached_stdout method. This is necessary because
when a Java process is terminated, its standard output is no longer available.public boolean timed_out()
public long timeout_msecs()
public void destroy()
destroy
in class java.lang.Process
Process.destroy()
public int exitValue()
exitValue
in class java.lang.Process
Process.getErrorStream()
public java.io.InputStream getErrorStream()
getErrorStream
in class java.lang.Process
Process.getErrorStream()
public java.io.InputStream getInputStream()
getInputStream
in class java.lang.Process
Process.getInputStream()
public java.io.OutputStream getOutputStream()
getOutputStream
in class java.lang.Process
Process.getOutputStream()
public int waitFor() throws java.lang.InterruptedException
waitFor
in class java.lang.Process
java.lang.InterruptedException
Process.waitFor()
public boolean finished()