Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forking a process in Java

Tags:

java

runtime

Is it possible to create a complete fork of a 'PROGRAM' in execution into two sub-programs from a single execution sequence ?

The sub-programs produced are completely identical. They have the same execution sequences and values but now they are two different programs. It is like creating a clone of an Object, thus giving us two different objects of the same type to work on. But instead of just an object and some values, here we want to create a completely parallel execution sequence of a Program already loaded in the JVM (would prefer an answer for Java).

like image 700
Mohan Krishna Avatar asked Dec 23 '22 11:12

Mohan Krishna


1 Answers

You seem to be looking for the Java equivalent of the fork system call from Unix.

That does not exist in Java, and it's unclear whether it would even be possible, as processes in Unix don't have a direct equivalent in the JVM (threads are less independent than processes).

There is however a fork framework planned for Java 7:

http://www.ibm.com/developerworks/java/library/j-jtp11137.html

It's not the same as Unix'es fork/join, but it shares some ideas and might be useful.

Of course you can do concurrent programming in Java, it's just not done via fork(), but using Threads.

like image 134
sleske Avatar answered Dec 31 '22 11:12

sleske