我有两个程序,第一个程序用processbuilder启动第二个程序。
第二个程序单独运行的时候就能正常。
但被第一个程序启动的时候,有时会死锁
反正就是没反应,但从任务管理器上看确实多了个java程序。
我试着用jconsole连接那个程序,也连不上。用jstack也没反应。
但有时候第二个程序也会正常启动,具体为什么我一直不太明白。开始一直怀疑和内存有关。
因为我把启动第二个程序的时候java命令后面的内存设置修改了之后,有时候会好。
但换台机器又没不好用了。后来感觉和内存也没什么关系了。谁有这方面的经验,能不能提点我一下。

解决方案 »

  1.   

    关键是单独运行第二个程序没问题。
    因为使用了processbuilder,所以两个程序应该在两个JVM中。
    所以才感觉非常奇怪啊。
      

  2.   

    刚才查了一下API,process里面有下面这段话,感觉可能是因为我没有处理输出流造成的。
    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.