Java - C-Like Fork?

Is it possible to do a "C like" fork in java, using an new independent jvm process ?


Asked by: Sawyer796 | Posted: 28-01-2022

Answer 1

This answer is probably a little late but:

seems to be exactly what your looking for

Answered by: Paul133 | Posted: 01-03-2022

Answer 2

Funnily, I am just working on this: a Java process running other Java processes. I used the article From Runtime.exec() to ProcessBuilder as a solid base, and When Runtime.exec() won't as a good advice how to gobble the output streams.

PS.: For those wondering, I had to do that (instead of spawning new threads) because yet another Java process is checking the presence of these processes which are, normally, ran separately with shell commands.

Answered by: Brooke351 | Posted: 01-03-2022

Answer 3

The Application Isolation API (JSR 121) introduces Isolate which addresses this use case.

Answered by: Dominik591 | Posted: 01-03-2022

Similar questions

Is there a a C-like way to get item number from enum in java?

Perhap this is a simple basic question Having an enum public enum TK{ ID,GROUP,DATA,FAIL; } Can I get the order number for example ID=0, GROUP=2, DATA=3, FAIL=4 ? This is a way to to that, but a weird and long one! =S public enum TK{ ID(0),GROUP(1),DATA(2),FAIL(3); int num; TK(int n) { this.num=n; ...

c++ - C-like enum in Java

I'm trying to find a Java equivalent for the following convenience in C++: enum { ANIMAL_CAT = 0, ANIMAL_RAT, ANIMAL_BAT, ... NUM_ANIMALS }; Animal animals[NUM_ANIMALS]; animals[ANIMAL_CAT].mNumLegs = 4; animals[ANIMAL_RAT].mNumLegs = 4; ... I know this isn't the prettiest thing in the world, but I can add a new ANIMAL_xxx anywhere in the enum and all the following entries will b...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)