当多个java程序在同一台机器上运行时 [英] When multiple java programs run on the same machine

查看:304
本文介绍了当多个java程序在同一台机器上运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个Java应用程序都将在特定的Java虚拟机实例中运行。我真的对以下方面感到困惑,谷歌搜索让我更加困惑。不同网站上的不同文章。

Each java application will run in a specific Java Virtual Machine Instance. I am really getting confused on below aspects and Googling has confused me even more. Different articles on different sites.


  1. 如果我有一个用java编写的Web服务,它将需要一个JVM实例来运行。所以是否可以将JVM作为守护进程?

  1. If I have a web service written in java it will need a JVM instance to run.So can JVM be made a daemon process?

如果我们运行任何其他Java应用程序,它将使用此JVM实例或创建一个新实例?

If yes when we run any other java application it will use this instance of JVM or create a new one?

任何机器中可用的主存储器都是常量。当我们同时启动n个java进程而不提供任何初始堆大小时,如何在进程间分配堆大小?

Main memory available in any machine is constant. When we start n java processes simultaneously without providing any initial heap size how is the heap size distributed among processes?

是否有任何进程管理n个JVM实例或它是由操作系统本身管理的?

Is there any process that manages n number of JVM instances or is it managed by OS itself?

当在GC期间发生停止世界时,其他JVM实例(我假设的不同线程)是否受到影响?

When stop-the-world happens during an GC are other JVM instances(different threads I assume) affected?


推荐答案


1)如果我有网络用java编写的服务需要运行JVM实例。那么JVM可以成为守护进程吗?

1) If I have a web service written in java it will need a JVM instance to run. So can JVM be made a daemon process?

是的它可以。如何完成取决于O / S和Web服务器容器本身。

Yes it can. How it is done depends on the O/S and on the web server container itself.


2)如果是,当我们运行任何其他java时应用程序它将使用此JVM实例或创建一个新的?

2) If yes when we run any other java application it will use this instance of JVM or create a new one?

否。每个Java应用程序都使用独立的JVM。

No. Each Java application uses an independent JVM.

每个JVM都是一个单独的进程,这意味着没有堆栈,堆等共享。 (通常,可以共享的唯一内容是包含核心JVM和本机库代码的只读段......与正常流程可能共享代码段的方式相同。)

Each JVM is a separate process, and that means there is no sharing of stacks, heaps, etcetera. (Generally, the only things that might be shared are the read only segments that hold the code of the core JVM and native libraries ... in the same way that normal processes might share code segments.)


3)任何机器中可用的主存储器都是常量。当我们同时启动n个java进程而不提供任何初始堆大小时,如何在进程之间分配堆大小?

3) Main memory available in any machine is constant. When we start n java processes simultaneously without providing any initial heap size how is the heap size distributed among processes?

决定如何如果不指定大小,则生成堆的大小取决于您使用的JVM /平台/版本,以及您是使用客户端还是服务器模型(对于Hotspot JVM)。启发式算法没有考虑其他JVM的数量或大小。

The mechanism for deciding how big to make the heap if you don't specify a size depends on the JVM / platform / version you are using, and whether you using the "client" or "server" model (for Hotspot JVMs). The heuristic doesn't take account of the number or size of other JVMs.

参考: https://stackoverflow.com/a/4667635/139985

实际上,最好直接指定堆大小。

In practice, you would probably be better off specifying the heap size directly.


4)是否存在管理n个JVM实例的任何进程,或者它是否由操作系统本身管理?

4) Is there any process that manages n number of JVM instances or is it managed by OS itself?

两者都没有。 JVM实例的数量由可以启动进程的各种操作决定;例如守护程序脚本,命令脚本,用户在命令行键入命令,等等。最终,如果资源耗尽,操作系统可能会拒绝启动任何更多进程,但JVM与其他进程的处理方式不同。

Neither. The number of JVM instances is determined by the actions of various things that can start processes; e.g. daemons scripts, command scripts, users typing commands at the command line, etcetera. Ultimately, the OS may refuse to start any more processes if it runs out of resources, but JVMs are not treated any different to other processes.


5)当在GC期间发生停止世界时,其他JVM实例(我假设的不同线程)是否受到影响?

5) When stop-the-world happens during an GC are other JVM instances(different threads I assume) affected?

否。 JVM是独立的进程。他们不共享任何可变状态。垃圾收集在每个JVM上独立运行。

No. The JVMs are independent processes. They don't share any mutable state. Garbage collection operates on each JVM independently.

这篇关于当多个java程序在同一台机器上运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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