|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread openlsd.common.LSDStreamGobbler
public class LSDStreamGobbler
Class to make a fix for Runtime.exec bug.
The API was not really well documented but now there is at least a warning (as of the 1.6 version) in the Process API:
"All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three
streams (getOutputStream(), getInputStream(), getErrorStream()). The parent process uses these streams to feed input
to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard
input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may
cause the subprocess to block, and even deadlock."
What does this means ? Well, if you launch a process but you don't care about its ErrorStream for instance and so you
don't try to read anything from it, you likely will have a chance to block the subprocess and even the main JVM, so
having a deadlock. To avoid this, I use a specific thread to read from error stream and input stream (read anything
without action), the StreamGobbler class.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
int |
status
Returned status |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
LSDStreamGobbler(java.io.InputStream is)
Init from only an IntputStream |
|
LSDStreamGobbler(java.io.InputStream is,
java.io.OutputStream redirect)
Init from InputStream and OutputStream |
|
LSDStreamGobbler(java.lang.Process p)
Init from only a Process without taking into account InputStream. |
Method Summary | |
---|---|
void |
run()
Run the StreamGobbler or Wait for the process to finish, reading any err data. |
static int |
waitForProcess(java.lang.Process p)
Wait for the process to finish, reading any in/err data |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public int status
Constructor Detail |
---|
public LSDStreamGobbler(java.lang.Process p)
p
- public LSDStreamGobbler(java.io.InputStream is)
is
- public LSDStreamGobbler(java.io.InputStream is, java.io.OutputStream redirect)
is
- redirect
- Method Detail |
---|
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public static int waitForProcess(java.lang.Process p)
p
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |