问题描述
通过阅读这篇文章,我知道每个java应用程序都会在特定的 Java 虚拟机实例.所以如果我执行以下命令("Java -jar test1.jar","Java -jar test2.jar",我会得到系统中的两个进程.并且如果每个命令都使用默认的堆大小,例如256M.总内存成本是512M,对吗?我还有其他问题:
By reading this article, I know that each java application will run in a specific Java Virtual Machine Instance. So if I execute the following commands("Java -jar test1.jar","Java -jar test2.jar", I will get two processes in the system. And If each command used the default heap size, for example, 256M. The total memory cost is 512M, is that right? Also I have other questions:
- Java虚拟机是守护进程,随系统启动?
- 当我执行java -jar test1.jar"时,它会创建一个Java虚拟机实例,然后执行main函数.是不是每一个运行的java应用都是Java虚拟机的一个子线程或者进程?
- 每个正在运行的 java 应用程序都是独立的,其他应用程序无法从这个正在运行的 java 应用程序中获取变量、方法、常量等吗?
- 如果一个正在运行的 java 应用程序崩溃,是否会影响其他正在运行的 java 应用程序?
PS:我搜索了很多不同的答案,我完全糊涂了.任何可以帮助我解决此类问题甚至更深入的Java虚拟机的人.例如,它是如何工作的.
PS: I googled and got lots of different answers, I was totally confused. Anyone who can help me on this kind of questions or even more depth of Java virtual Machine. For example, How it works.
推荐答案
JVM 是一个标准进程,就像其他任何进程一样.因此,两者之间没有隐含的通信或状态共享.每个都有自己的堆、线程等.如果你杀死一个,它不会影响另一个.
The JVM is a standard process, just like any other. As such there's no implicit communication or state sharing between the two. Each will have their own heap, threads etc. If you kill one it won't affect the other.
将共享的是 JVM 本身的代码页.内核足够智能,可以识别运行两次的相同二进制文件(any 二进制文件 - 不仅仅是 JVM)并重用映像.这仅适用于实际的二进制代码 - 而不是它的状态.请参阅此处了解更多信息.Linux.
What will get shared are the code pages of the JVM itself. The kernel is intelligent enough to identify the same binary (any binary -not just the JVM) running twice and reuse the image. This only applies to the actual binary code - not its state. See here for more info re. Linux.
JVM 不是守护进程,但可以在系统启动时作为 Windows 服务或 Unix/Linux 进程启动(通过 /etc/init.d
脚本).这就是您(比如说)在机器启动时运行用 Java 编写的 Web 服务的方式.
The JVM isn't a daemon process, but could be started upon system startup as a Windows service or Unix/Linux process (via /etc/init.d
scripts). This is how you'd (say) run a web service written in Java when a machine is booted up.
这篇关于java虚拟机在执行多个java应用程序时会做什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!