Many java processes on jvm?

If I want to run several processes in one jvm without synchronization (I don't care that several things work at the same time ... I just want to avoid restarting jvm), what is the best solution?

Starting one thread and connecting to wait until it dies, and then create another thread to perform another task?

+3
source share
9 answers

Reminds me of JSR 121 Isolates . This specification is complete, but I'm not sure if anything ever happened to the implementation of this stuff. There is a continuation of JSR 284 .

+4
source

Ant Java Java JVM - , fork false ( ). .

+3

/ . , , . , .

Java, , . JVM. , JVM , , JVM. , , JVM.

+1

, , (.. jar , java) java-, jvm . BeanShell, , .

:

java -cp bsh-2.0b4.jar;yourapp.jar bsh.Console

,

bsh % com.domain.prog.Mainclass.main( new String[] { } );
+1

Runtime.exec Process, . Process , , , () .

0

JVM; JVM ( , ). , JVM.

0

, , , . , . , Runnables. run(), , , , start():

public class T1 extends Thread {
   public void run () { .. do something useful .. }
}

public class T2 extends Thread { ... yadda yadda }

public static void main (String args[] )
{
 new T1().start();
 new T2().start();
}
0

A.) / , , , , Classloaders/Reflection (String [] args) , .

0

You do not even need threads to sequentially run a number of other Java programs:

public class RunPrograms {

   public void main(args) {
      <for each applicationClass and args> {
        try {
           applicationClass.main(args)
        } catch Exception e {
           // if you want the entire set to die if one dies, rethrow (or don't catch)
           // otherwise somehow log the error and continue
        }
      }
   }
}

You will have problems if any of the programs causes System.exit(), but this will be true for any system using one jvm.

0
source

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


All Articles