Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Virtual Machine: Shared or does have every application it's own? [duplicate]

Tags:

java

If I start a Java application on a physical machine and then I start a second Java application, a third application ... etc.

Is every time a new Java Virtual machine started. So that every app has it's own JVM?

Or is the memory allocated for the first JVM enlarged by the operating system of the physical machine and all apps run in one JVM? So that there will be always only one JVM.

like image 260
cluster1 Avatar asked Apr 16 '26 22:04

cluster1


2 Answers

Actually when you "start an application", what you're doing is starting a new JVM and telling it to execute a class through the command line arguments.

However, in web applications executed inside a servlet container, each app will have it's own classloader, therefore they won't share the content of static variables. That could give you the impression that each runs on a different JVM.

like image 178
Andres Avatar answered Apr 18 '26 12:04

Andres


JVM — instance of JRE. When you run application - new JVM is initialized. After application finished - the instance is removed by garbage collector.

like image 20
Pavlo Plynko Avatar answered Apr 18 '26 11:04

Pavlo Plynko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!