public static interface BaseDataReader.SleepingPolicy
InputStream.read()
.
(Async approach like SelectableChannel
is not supported for process's streams,
although some native api may be used).
Thread stays blocked by InputStream.read()
until some data arrived or stream is closed (because of process death).
It may lead to issues like IDEA-32376
: you can't unlock blocked thread (at least non-daemon) otherwise than by killing
process (and you may want to keep it running). Thread.interrupt()
doesn't work here.
This approach is good for short-living processes.
If you know for sure that process will end soon (i.e. helper process) you can enable this behaviour using BLOCKING
policy.
It is implemented in BaseDataReader.readAvailableBlocking()
InputStream.available()
to see how much data can be read without of blocking.
This gives us ability to use simple loop
InputStream.available()
InputStream.read()
} which is guaranteed not to block processTerminated
flag set then exit loopNON_BLOCKING
(aka non-blocking) policy. Drawback is that process may finish (when Process.waitFor()
returns)
leaving some data unread.
It is implemented in BaseDataReader.readAvailableNonBlocking()
}
BLOCKING
.
For user process that may run forever, even after idea is closed, and user should have ability to disconnect from it
use NON_BLOCKING
.
If you see some data lost in stdout/stderr try switching to BLOCKING
.
Modifier and Type | Field and Description |
---|---|
static BaseDataReader.SleepingPolicy |
BLOCKING |
static BaseDataReader.SleepingPolicy |
NON_BLOCKING |
static BaseDataReader.SleepingPolicy |
SIMPLE
Deprecated.
use
NON_BLOCKING instead |
static int |
sleepTimeWhenIdle |
static int |
sleepTimeWhenWasActive |
Modifier and Type | Method and Description |
---|---|
int |
getTimeToSleep(boolean wasActive) |
static final int sleepTimeWhenWasActive
static final int sleepTimeWhenIdle
static final BaseDataReader.SleepingPolicy NON_BLOCKING
static final BaseDataReader.SleepingPolicy BLOCKING
@Deprecated static final BaseDataReader.SleepingPolicy SIMPLE
NON_BLOCKING
instead