Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many JVM instances will create when we issue java command in different command prompts?

Tags:

java

jvm

cmd

Can anyone please tell me how many jvm instances will created when we issue the following commands in different commands.

- command 1: c:\java -Xms32m -Xmx512m -Xss254k AccountSalary
- command 2: d:\java -Xms32m -Xmx512m -Xss254k AccountSalary
- command 3: c:\java -Xms32m -Xmx512m -Xss254k AccountSalary

Whether they will use save jvm heap size or for each java process different heap size?

like image 479
Rajasekhar Burepalli Avatar asked Mar 06 '14 09:03

Rajasekhar Burepalli


People also ask

How many JVM instances can run on a machine?

Infinite! Multiple JVMs can run on a single machine, as for example, for execution of applets a separate JVM may exist and another JVM can be started by the User for execution of Java Byte Code, on a single machine.

How do I run multiple JVM instances?

you can have as many jvm as you can running on a single machine as every java.exe or javaw.exe will star a new jvm. and regarding calling a method u can use RMI. Show activity on this post. Yes you can run multiple VMs on the same machine.

How JVM instance is created?

An implementation Its implementation is known as JRE (Java Runtime Environment). Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is created.

Does java command start new JVM?

Each java invocation starts its own JVM.


Video Answer


1 Answers

Each time you run the java command, you create a new JVM instances. (And each JVM instance will be a distinct process.)

So, in your example, the number of JVM instances will be 3.

JVM instances do not share heaps. Each one will have its own heap. There is no saving of heap space by creating multiple heaps. (In fact you probably use more heap space by creating multiple JVMs ... compared with running 3 instance of your application in the same JVM using multi-threading.)

The heap sizes are independent. They are determined by the individual JVMs' command line options ...


With most JVMs, the only memory that is shared between JVM instances is the read-only segment containing the JVM code, and (possibly) shared native libraries.

Historically, there have been JVMs where compiled Java code can be shared between JVMs. However, it is complicated, and (AFAIK) current generation JVMs don't support this.

like image 178
Stephen C Avatar answered Oct 13 '22 07:10

Stephen C