-1

When using ProcessBuilder, is there a true non blocking reactive way to consume the output? By true non blocking i mean not creating a thread that is blocked waiting to read, but push-based like NodeJS streams. Thank you.

I would like to avoid to create a new thread for every process launch due to concurrency and memory concerns, neither do i want to block an existing thread that might be used for http clients.

6
  • 1
    Can you not create a dedicated thread to read the process output, segment it, and then "push" the segments to wherever you need them to be pushed to? If the end result is that the output gets "pushed," then how does the existence of the thread that pushes them cause a problem for you? Commented Jul 8 at 16:43
  • 1
    You may find inheritIO() useful. Commented Jul 8 at 16:51
  • That would only block a different thread, it's not really low footprint reactive code. Also i mean to pipe the output so inheritIO is useful indeed but it wont be enough alone
    – dac1n
    Commented Jul 8 at 17:09
  • seems like one of the goals of Virtual Threads... JEP 444 (many blocked requests)
    – user85421
    Commented Jul 8 at 18:07
  • 1
    Re, "I would like to avoid to create a new thread for every process launch" @user85421 said, "Virtual Threads" They are cheap. That's their whole point. The cost of creating a new virtual thread is in the same ball park as the cost of creating any other Java object—insignificant compared to the cost of creating the process that the thread would serve. Commented Jul 8 at 19:50

0