1) Primary is another class in my project and is executable...
2) I try to start its main method in the following way:
Process proc = Runtime.getRuntime().exec("java Primary");
or:
String[] cmdArray = {"java", "Primary"};
Process proc = Runtime.getRuntime().exec(cmdArray);
3) Then I try to read process' streams in a separate thread.
4) In the main thread program stops at proc.waitFor() and execution
doesn't resume...
5) In the "reading" thread, the function which blocks execution is
BufferedReader.readLine() (I would rather expect it to return null in
the worst case... but I have even used the BufferedReader.ready()
method and I believe I wait if the buffer is empty...)
6) Nothing happens, the program can't finish...
I've been already asking about the apporach I use:
http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/11e367a28a0b41fd/9d69aa5ef2e34211
And I know this (very good, in my opinion) article:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
First, I wanted to test notions of visibility between Java executable
classes when invoking my program both from NetBeans IDE and as a JAR
from command line... But I can't do it (as I described above).
What is wrong in my approach?
Thanks in advance for your help.
MR
A single thread for both output streams, or a thread for each stream?
Patricia
A single thread. Now I know that is possible, but tricky! :D
One of the streams were empty all the time and it was blocking! The
main reason was that first I was waiting until any of the streams is
ready and then, incidentally, I was trying to read from unready
stream :)
Now I can ask about my main problem... but in a separate thread!
MR
To me, this seems like unnecessary trickiness, compared to the cost of
either using two threads, or using ProcessBuilder to combine the streams.
Patricia