首页 编程技术在solaris上慎用Runtime.getRuntime().exec()

在solaris上慎用Runtime.getRuntime().exec()

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的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

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

  1. Simon说道:

    没看到是哪个版本解决这个bug呀?

  2. Lin说道:

    目前JDK1.6.0_32还未解决此问题,JDK7有没有解决就不知道了

  3. admin说道:

    这个是和操作系统有关吗?Solaris和Java都是Sun自己的,兼容性测试不充分啊。。。

  4. Lin说道:

    嗯,应该也和操作系统底层有关,目前只在Solaris上出现过,linux和windows还未出现

  5. XiaoMing说道:

    有什么替代办法吗

    • Simon说道:

      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/

Copyright © 2012-2022 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部