What does it mean to have a forked Java virtual machine?

I sometimes get this error when I run JUnit tests.

I do not quite ask what kind of mistake this is. I just want to know what that means when Java forks Java?

+6
source share
2 answers

A โ€œbranched virtual machineโ€ is not an error (although the resulting error 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.

If you run unit tests for your application without overlapping a virtual machine, Maven will run those tests within the same virtual machine as Maven. Therefore, it can be affected by some settings of the virtual machine (for example, some system properties).

To avoid side effects due to Maven, you can run tests in a forked virtual machine, that is, in a completely separate virtual machine that runs as another process in the OS.

(This applies to other tools, Maven is an example).

The forked virtual machine crashes, at least, allows you to return to another Java application that launched and organized these unit tests. If you ran these tests in the same virtual machine, you would also break the application that ran your tests (and thus get very little information in return).

+19
source

A ' fork ' is the terminology used in Linux to mean the execution of another process (freely). In this case, the forked Java virtual machine 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 several forking modes, which can be seen here .

I saw errors indicating that the forked virtual machine died while using JUnit. This means that your test fails and that your JUnit runner (usually ant) โ€‹โ€‹cannot get any output.

You should try to resolve the cause of the failure.

+2
source

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


All Articles