Process shaping in Java

Is it possible to create the full version of "PROGRAM" when executed in two subprograms from the same execution sequence?

The resulting routines are completely identical. They have the same execution sequences and meanings, but now they are two different programs. This is similar to creating a clone of an object, which gives us the opportunity to work with two different objects of the same type. But instead of a simple object and some values ​​here, we want to create a completely parallel sequence of execution of a program already loaded in the JVM (prefer an answer for Java).

+3
source share
4 answers

, Java fork Unix.

Java, , , Unix JVM ( , ).

Java 7 fork:

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

, Unix'es fork/join, .

, Java, fork(), Threads.

+7

, . , , -. - ?

public class MyApp implements Runnable
  {
  public MyApp(int foo, String bar)
    {
    // Set stuff up...
    }

  @Override
  public void run()
    {
    // Do stuff...
    }

  public static void main(String[] argv)
    {
    // Parse command line args...

    Thread thread0 = new Thread(new MyApp(foo, bar));
    Thread thread1 = new Thread(new MyApp(foo, bar));

    thread0.start();
    thread1.start();
    }
  }

, , main() , .

+4

, ProcessBuilder, .

. Java- fork Java Ant?

+1

, .

+1

Source: https://habr.com/ru/post/1708259/


All Articles