什么启动 JVM 线程?

发布于 2024-09-29 22:26:53 字数 554 浏览 0 评论 0原文

(如果我错了,请纠正我)

我明白,当你通过发出java命令来运行java程序时,

java MyProg

该程序将在新的JVM上运行。

  • 什么将程序加载到新的 JVM 中?是 JRE 产生新线程吗?

  • 如果每个程序都运行在自己的JVM中,它们之间是否可以相互通信?

  • 我之前问过一个关于如何使用 JMX 向本地运行的 java 程序发送请求的问题。我发现如果 JMX 命令是在本地发出的,我不需要端口号。答案是客户端应用程序(例如jconsole、jvisualvm、jprobe 等)搜索机器上运行的java 应用程序。这很好,但考虑到客户端应用程序将在与其想要监视或与之通信的应用程序不同的 JVM 中运行,那么它们在没有端口号的情况下究竟如何相互交互(因为它们不在同一个 JVM 上运行)?

  • 如果运行两个程序,通常会有 2 个 JVM。 JVM 是否在同一个 JRE 进程中运行?这是否意味着两个 JVM 应该能够通信?

谢谢

(Please correct me if i am wrong)

I understand that when you run a java program by issuing the java command,

java MyProg

the program will be run onto a new JVM.

  • What loads the program into a new JVM? is it the JRE that spawns a new thread?

  • If each program runs in its own JVM, is it possible for them to communicate with each other?

  • I asked a question earlier on how to use JMX to send requests to a java program running locally. I found out that if the JMX commands are issued locally i dont need a port number. The answer was that the client application (e.g. jconsole, jvisualvm, jprobe etc) searches for java applications running on the machine. This is fine but given that the client application will run in a different JVM from the application it wants to monitor or talk to, how exactly do they interface with each other without a port number (since they are not running on the same JVM)?

  • If two programs are running there will usually be 2 JVMs. Do the JVMs run within the same JRE process? And also wouldnt this mean that the two JVMs should be able to communicate?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

原谅过去的我 2024-10-06 22:26:53
  • 程序(更具体地说是编译后的类)由 JVM 中称为系统类加载器的组件加载。 (在此处了解有关类加载器的更多信息)。 JVM 使用本机代码库(由引导类加载器加载)来生成新线程。
  • 它们可以使用套接字、RPC 和其他 IPC 机制(通常使用本机库访问)进行通信。
  • 不知道确切的答案,但一定有一个标准端口。
  • JVM 的不同实例是单独的进程。他们在内存中没有任何共享。 (不过,如果在同一系统上运行,它们可能会共享同一 JRE 安装的库和配置文件。这与在同一系统上运行 Firefox、Emacs 或其他应用程序的两个实例没有什么不同)。
  • The program (more specifically the compiled class) is loaded by a component in the JVM called the System Class Loader. (Read more about class loaders here). The JVM uses the native code libraries (loaded by the bootstrap class loader) to spawn a new thread.
  • They can communicate using sockets, RPC and other IPC mechanisms (usually accessed using native libraries).
  • Don't know the exact answer, but there must be a standard port.
  • Different instances of the JVM are separate processes. They share nothing in-memory. (Though, if running on the same system, they might share libraries and configuration files of the same JRE installation. This is no different from running two instances of Firefox, Emacs or some other application on the same system).
野心澎湃 2024-10-06 22:26:53

幕后并没有什么特殊的魔法。 java是实现JVM的程序。如果您同时使用两个不同的程序(例如,在两个不同的 shell 中)运行 java,则会得到两个运行各自 JVM 的进程。它们可以通过您喜欢的任何 IPC 或网络协议进行通信。

There is no special magic going on behind the scenes. java is a program that implements the JVM. If you concurrently run java with two different programs (in two different shells, say), you get two processes running their own JVMs. They may communicate via whatever IPC or networking protocol takes your fancy.

已下线请稍等 2024-10-06 22:26:53

不同jvm中的程序通信有以下几种方式:

  1. ObjectInputStream、ObjectOutputStream

  2. RMI

  3. sockets

There are several ways for programs in different jvms to communicate:

  1. ObjectInputStream, ObjectOutputStream

  2. RMI

  3. sockets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文