开发者

Using Java to spawn a process and keep it running after parent quits

开发者 https://www.devze.com 2022-12-26 00:54 出处:网络
As the title suggests is it possible to execute another java app from within a java app and kee开发者_如何学Cp the children running after main application quits?I guess you could do

As the title suggests is it possible to execute another java app from within a java app and kee开发者_如何学Cp the children running after main application quits?


I guess you could do

Runtime.getRuntime().exec(command);

where command is a java command


Maybe make the sub-process a service?


If you want to quit the JVM together with the main application, then use Fortega's suggestion (it's probably the best way to do it)!

There's also another approach, if you don't want to create new processes: You could run everything in a separate Thread, also the "main application". This would not exit the Java Virtual Machine, and the threads would run until they're finished (except if you set them up as Daemon threads).

0

精彩评论

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