Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does calling java create new JVM instance or just another Java process?

Tags:

java

jvm

Whenever we start a Java program:

java Herpyl.java -derp

Is this creating another JVM instance, or another Java process on top of the same JVM instance? I'm confused as to the relationship between JVM and "Java" or a "Java process". Thanks in advance!

like image 612
IAmYourFaja Avatar asked Jan 17 '23 20:01

IAmYourFaja


1 Answers

Each java invocation starts its own JVM.

Sharing one JVM between processes has problems wrt security and stability: If one process kills the JVM you also killed the other and the other process really shouldn't be able to read/modify the data of the other process without the right rights (don't forget you can call arbitrary JNI code from your java process).

If you're worried about memory consumption: Yes that does indeed increase the memory, but any modern OS will map different dlls and other things - on my win7 x64 machine an idle javaw process has a private workingset of ~300kb.

like image 172
Voo Avatar answered Jan 30 '23 20:01

Voo