什么启动 JVM 线程?
(如果我错了,请纠正我)
我明白,当你通过发出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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
幕后并没有什么特殊的魔法。
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 runjava
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.不同jvm中的程序通信有以下几种方式:
ObjectInputStream、ObjectOutputStream
RMI
sockets
There are several ways for programs in different jvms to communicate:
ObjectInputStream, ObjectOutputStream
RMI
sockets