Streams of Irony

As I’ve mentioned before, I seem to have problems with very long command lines, e.g. when I try to do a javac ${drjava.all.files;sep=" ";rel="${project.root}"}. With really long command lines, it seems like the project is started, and ps also shows the process, but it never does anything, nor produce output.

The fact that it never produced any output was actually good, because it made me notice that in that case, my previous implementation hangs. I was doing the reading in the AWT event thread, and if there was no output from the external process, the event thread would be blocked until output was available. I moved the actual reading from the stream into a separate thread.

When I abort a process, though, I would like to read whatever is available from the process right now, but of course I don’t want to block the event thread. I only want to read if output is available, and Java is nice enough to provide the InputStreamReader.ready() method for this purpose.

The documentation of ready() states:

Returns: True if the next read() is guaranteed not to block for input, false otherwise.

That may be true, but in my case, the call to ready() itself blocks, so finding out whether the next call to read() will block is pointless.

The alternative, InputStream.available() also blocks, even though the documentation states:

Returns: the number of bytes that can be read from this input stream without blocking.

Shouldn’t method which tell you if your program will block or not be written in a way so they themselves do not block? Sigh.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in DrJava, Ramblings. Bookmark the permalink.

Leave a Reply