Runtime.getRuntime().exec() ... mad buffering of stdout ...
It buffers stdout without limit ...
so if your Java program doesn't keep up with the Process output then
memory fills up!
I wish it just blocked instead because my Java program is loosing
the race against the C program that it exec()s.
The pattern I want is "producer-consumer"
and i'm suprised that it seems imposible.
what can I do?
Here is a small example that illustrates the issue ...
5523:fosters:~: cat Test.java
class Test {
public static void main(String[] args) {
try {
Process p =
Runtime.getRuntime().exec("/usr/bin/yes");
for (;;) {
Thread.sleep(1000);
System.out.println("tick");
Thread.sleep(1000);
System.out.println("tock");
}
}
catch (Exception x) {
x.printStackTrace();
}
}
}
5524:fosters:~: rm *.class
5525:fosters:~: /usr/local/IBMJava2-13/bin/javac Test.java
5526:fosters:~: /usr/local/IBMJava2-13/bin/java Test
tick
tock
tick
tock
java.lang.OutOfMemoryError
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
tock
tick
[etc....]