java虚拟机在执行多个java应用程序时将执行的操作 [英] what java virtual machine will do while executing multiple java applications

查看:497
本文介绍了java虚拟机在执行多个java应用程序时将执行的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过阅读文章,我知道每个java应用程序都将在特定的Java虚拟机实例。因此,如果我执行以下命令(Java -jar test1.jar,Java -jar test2.jar,我将在系统中获得两个进程。并且如果每个命令使用默认堆大小,例如256M。总内存成本是512M,是吗?
我还有其他问题:




  • Java虚拟机是守护进程吗?进程,启动系统?

  • 当我执行java -jar test1.jar时,它将创建一个Java虚拟机实例,然后执行main函数。是否意味着每个运行的java应用程序都是Java虚拟机的子线程或进程?

  • 是每个运行java应用程序的个体,其他应用程序无法获取变量,方法,常量等,从此运行java应用程序?

  • 如果一个正在运行的java应用程序崩溃了,它会影响其他正在运行的java应用程序吗?



< PS:我用谷歌搜索并得到了很多不同的答案,我完全糊涂了。任何可以帮助我的人有点问题甚至更深入的Java虚拟机。例如,它是如何工作的。

解决方案

JVM是一个标准流程,就像其他任何流程一样。因此,两者之间没有隐含的沟通或国家共享。每个人都有自己的堆,线程等。如果你杀了一个它不会影响另一个。



分享的是JVM本身的代码页。内核足够智能,可以识别运行两次的相同二进制文件(任何二进制文件 - 而不仅仅是JVM)并重用图像。这仅适用于实际的二进制代码 - 而不是其状态。有关详细信息,请参见此处。 Linux。



JVM不是守护进程,但可以在系统启动时作为Windows服务或Unix / Linux进程启动(通过 /etc/init.d 脚本)。这就是你在启动计算机时运行用Java编写的Web服务的方式。


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:

  • Is the Java virtual Machine a daemon process, start up with the system?
  • When I execute "java -jar test1.jar", it will create an instance of Java Virtual Machine, then execute the main function. Does it mean every running java application is a sub thread or process of Java Virtual Machine?
  • Is each running java application individual, other application can not get variable, method, constant, etc, from this running java application?
  • If one running java application is crashed, will it affect other running java application?

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.

解决方案

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.

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.

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应用程序时将执行的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆