Java process.getInputStream() has nothing to read, deadlocks child

隐身守侯 提交于 2019-12-05 02:08:22

You need to use a threadsafe data structure; I don't think LinkedList is threadsafe.

One mistake that strikes me is that LinkedList is not synchronized, but you're trying to write to it in 2 threads.

Another thing to keep in mind is Process.getInputStream() returns the stdout stream of the process, so you should rename the variable currently called stdin to stdout to prevent confusion.

There are known bugs in pre-Vista Windows operating systems where loading DLLs can cause a hang in IO.

e.g. see http://weblogs.java.net/blog/kohsuke/archive/2009/09/28/reading-stdin-may-cause-your-jvm-hang and https://connect.microsoft.com/VisualStudio/feedback/details/94701/loadlibrary-deadlocks-with-a-pipe-read

I'm not sure if this is what you are running in to, but it may be related.

Also, I vaguely recall some issues in getting a valid stdin and stdout from non-console windows applications. If your call to 'test.jar' is using 'javaw' rather than 'java', then this could be the cause of your problem, too.

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!