开发者

Stop external program when Java program is stopped

开发者 https://www.devze.com 2023-03-10 02:30 出处:网络
I\'m executing an external开发者_C百科 program which runs alongside Java using this: Process p = Runtime.getRuntime().exec(\"/path/to/binary\");

I'm executing an external开发者_C百科 program which runs alongside Java using this:

Process p = Runtime.getRuntime().exec("/path/to/binary");

When I stop the Java application, the external program continues to run but I want this to stop too.


To trigger the shutdown, you could add a shutdown hook to your Java application. See Runtime.addShutdownHook().

To effect the shutdown, you could either communicate to the external process a request to stop gracefully, or call Process.destroy()


use shutdown hook : http://download.oracle.com/javase/1.4.2/docs/guide/lang/hook-design.html

0

精彩评论

暂无评论...
验证码 换一张
取 消