开发者

What launches a JVM thread?

(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 ta开发者_StackOverflowlk 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


  • 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).


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.


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

  1. ObjectInputStream, ObjectOutputStream

  2. RMI

  3. sockets

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜