在solaris上慎用Runtime.getRuntime().exec()
2012-09-15 16:03
编程技术
阅读 26.8k
运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维
Java进程运行在Solaris上,如果代码中用了Runtime.getRuntime().exec(),启动一个子进程运行一些命令,可能出现子进程挂住,导致父进程退出时,父进程所占用的资源仍然没有释放,如端口等信息,用ps -ef仍然可以看到父进程的信息。用pstack可以看到fork信息,在Runtime.getRuntime().exec()挂住。
http://stackoverflow.com/questions/1160656/runtime-exec-causes-duplicate-jvm-to-hang-indefinitely-until-killed-solaris-10
http://bugs.sun.com/view_bug.do?bug_id=5049299
本文链接:https://www.yunweipai.com/945.html
没看到是哪个版本解决这个bug呀?
目前JDK1.6.0_32还未解决此问题,JDK7有没有解决就不知道了
自从sun被卖了oracle之后,Java的bug解决速度就很慢了。
这个是和操作系统有关吗?Solaris和Java都是Sun自己的,兼容性测试不充分啊。。。
嗯,应该也和操作系统底层有关,目前只在Solaris上出现过,linux和windows还未出现
有什么替代办法吗
bug单里面有写规避方法:
1) mkfile followed by swap -a to add more swap space
2) do Runtime.exec “early” in the application execution before the process has
grown so large (i.e. so the transient swap requirement between Runtime.exec’s fork and exec calls is big), cache resulting Process object, then replace
the “later” Runtime.exec calls that kicked off perl with println or the like to direct the aforementioned process exec perl with the same command line
and relay back the perl command’s standard output and error traffic.
3) Like (2) but spawn the “exec daemon” separate from Java to avoid any use of
Runtime.exec and instead communicate with Java via a pipe or socket to
initiate running the perl scripts.
exit status.
xxxxx@xxxxx 2004-05-19
4) Implement the “small” program in pure Java in order to avoid Runtime.exec()
5) Consider using a scripting engine, see also https://scripting.dev.java.net/