Reading Java without blocking

I am trying to read from two different input streams (stdin and stderr of a child application) and print them in one combined frame. I have never done this before, and I'm curious about best practices.

I can create two threads and let them block the input stream. Is there a better way?

Thank!

+3
source share
3 answers

Your approach is great, although if you are trying to combine two streams, you may run into problems when mixing output / error.

, Apache commons-exec, /. , , , InputStream (s).

+1

, .

-1

I think your best strategy would be to use classes in the java.nio package. Check this example out.

-2
source

Source: https://habr.com/ru/post/1756284/


All Articles