Hamza Yerlikaya
Hamza Yerlikaya

Reputation: 49329

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

As the title suggests is it possible to execute another java app from within a java app and keep the children running after main application quits?

Upvotes: 5

Views: 2442

Answers (3)

Chris Lercher
Chris Lercher

Reputation: 37778

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).

Upvotes: 0

JRL
JRL

Reputation: 77995

Maybe make the sub-process a service?

Upvotes: 0

Fortega
Fortega

Reputation: 19682

I guess you could do

Runtime.getRuntime().exec(command);

where command is a java command

Upvotes: 3

Related Questions