Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to have a forked java VM?

I sometimes get this error when I run the JUnit tests.

I'm not exactly asking what the error is. I just want to know what it means when the java VM forks?

like image 369
Dezrik Avatar asked Dec 15 '11 03:12

Dezrik


2 Answers

A "forked VM" is not an error (although the error you get may be related to it).

Some tools that are involved in various aspects of compilation and testing (e.g. Maven) are written in Java and use the JVM to run themselves.

If you run unit tests for your application without forking the VM, Maven will run those tests within the same VM as Maven is running. Therefore, it may be affected by certain VM-wide settings (e.g. some system properties).

To avoid side-effects due to Maven, it's possible to run the tests in a forked VM, that is, in a completely separate VM running as a different process in the OS.

(This can apply to other tools, Maven is just an example.)

Crashing a forked VM at least allows you to come back to the other Java application that started and orchestrated these unit tests. If you were running these tests within the same VM, you would also crash the application that launched your tests (and thus get very little information in return).

like image 89
Bruno Avatar answered Oct 26 '22 21:10

Bruno


A 'fork' is the terminology used in Linux to denote executing another process (loosely). In this case, a forked Java VM is a child process used to isolate your unit tests by class or method, ensuring that no state pollution occurs between multiple tests.

The JUnit ant task supports multiple forking modes as can be seen here.

I have seen errors that state that a forked VM has died when using JUnit. This means that your test is crashing and that your JUnit runner (usually ant) cannot get any of the output.

You should try to resolve the cause of the crash.

like image 43
Bringer128 Avatar answered Oct 26 '22 21:10

Bringer128