What Java virtual machine will run when running multiple Java applications

After reading the article, I know that each Java application will run in a specific instance of the Java virtual machine. Therefore, if I execute the following commands ("Java -jar test1.jar", "Java -jar test2.jar", I will get two processes on the system. And if each command used the default heap size, for example 256M. The total memory cost is 512 M, right? Also I have other questions:

  • Is the Java virtual machine a daemon process that starts with the system?
  • When I run "java -jar test1.jar", it will instantiate the Java virtual machine and then execute the main function. Does this mean that every running Java application is an auxiliary thread or process of a Java virtual machine?
  • Whether each java application is for a separate application, the other application cannot get a variable, method, constant, etc. from this running java application?
  • If one running java application is broken, will it affect another running java application?

PS: I googled and got a lot of different answers, I was completely confused. Anyone who can help me with this matter or even the deeper depth of the Java virtual machine. For example, How does it work.

+8
java jvm
source share
3 answers

JVM is a standard process like any other. Thus, between them there is no implicit connection or sharing by the state. Each will have its own pile, threads, etc. If you kill her, it will not affect the other.

What will become common is the code pages of the JVM itself. The kernel is smart enough to identify the same binary file (any binary file - not just the JVM) that works twice, and image reuse. This applies only to the actual binary code, and not to its state. See here for more details. Linux

The JVM is not a daemon process, but it can be started at system startup as a Windows service or as a Unix / Linux process (via the /etc/init.d scripts). So you can (say) run a web service written in Java when the machine boots up.

+7
source share

1) No, but there are ways to run java applications as services with wrappers (Google for the "Java service").

2) Yes.

3) You can use communication between processes (vg HTTP). But there are no shortcuts due to all the processes running in the JVM.

4) No

+2
source share

For the OS, JVM like an user application. Each JVM Instance is individual.

  • Not. JVM is a normal process, like others. But you can run it as a deamon process.
  • Yes. A Java application runs on the JVM just like your application on the OS.
  • Yes. Each JVM thread is individual, but they can communicate with other JVMs over a network, RMI ...
  • It depends. Usually they are individual, but if the JVM crashes cause the OS crash , other JVMs will run.
0
source share

All Articles