Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I spawn a JVM from a JVM that is easy to control and monitor?

Tags:

java

jvm

I want to span a new JVM process from a Java class.

I could use Runtime.getRuntime().exec(...) but this is a very low level api.

I am looking for something that will wrap that Process api for me in something a bit more convenient like:

MonitoredJavaProcess javaProcess = new MonitoredJavaProcess(MyMainClass.class, "-Xmx1g");
javaProcess.getGcLogStream();
javaProcess.getHeapSizeObserver();
// ...
javaProcess.waitForShutdown();

A bit context on what I am trying to do: I am running JUnit a test suite taht starts up an embedded Jetty server and runs some test against it. That means that the tested Jetty server threads and the junit test threads run in the same JVM. I need to run them i separate JVMs. I could use ant or maven or anything external to starup jetty and then run the test suite against it but it sound a bit of an overkill for my simple scenario.

like image 859
Wojtek B. Avatar asked Jan 29 '13 12:01

Wojtek B.


2 Answers

Perhaps your approach is not the right one. Perhaps you should consider using JMX to monitor your JVMs instead?

Cheers,

like image 183
Anders R. Bystrup Avatar answered Nov 05 '22 17:11

Anders R. Bystrup


What actually you are trying to do. May be you can look at java.lang.ProcessBuilder it might suite your need.

like image 39
Alankar Srivastava Avatar answered Nov 05 '22 16:11

Alankar Srivastava