Why does Java’s InputStream Close() will block?

My java program uses processbuilder (redirecterrorstream is set to true) and has a loop to run the read method of the InputStream of the process, which is blocked The external program I'm calling stops waiting for input and stdin I want to kill the process now Is this caused by calling the destroy method of the process (in a separate thread) and calling the close method of InputStream to prevent the read method from blocking, so that my initial thread can end its life?

For some reason, process getInputStream(). Close() block From Javadoc, I don't understand why this happens In addition, I don't understand why Javadoc says "the close method of InputStream does nothing" (link to Javadoc) can anyone explain?

Thank you: -)

Solution

With regard to blocking behavior, there is a known problem in Java that can cause deadlock when communicating with another process I don't know if this is what you see, but it's worth studying java. Lang. process file says:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>