jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes JVM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JVM" Watch "JVM" New topic


Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 141
I wanted to learn more about the JVM, and how it compares with a regular CPU + memory computing machine. In particular, I would like to know if it is possible to have multiple processes/programs running on the same VM and if they can share data. If possible, I would like to have some link from where I can learn more.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Try the Java Virtual Machine Specification.

You cannot have multiple processes on one JVM. A JVM is a single OS process, on all the platforms I've encountered. But you can, of course, have lots of threads. It is common for one JVM to host many "applications", via multi-threading.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 141

Just to clarify, can we have a single JVM execute two threads, each of which is an independent program? That is, can we have a single JVM running two main methods? And can we share data in this case?
Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
In general, as per the concept of threads,...Threads share all the resources of a process to which they are related ...and hence I do not think two threads of two diffrent processes can be run on a single JVM

Hareesh Ram Chanchali
SCJP 5.0, IBM Certified Solution Designer
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
This is not a problem...
All your "main" class needs is to either implement Runnable, or extend Thread. In any case the subsequent "implemented" method should call the Main of the required application.

For Example:

What I wanted to show is that in Java a thread is a thread is a thread. And a Class is a Class... ;-)

You can have a MAIN class who's job is to start other applications. Each such application will be treated equaly as a thread of the first MAIN application.

Each thread any of the applications will start will be treated by the JVM as if it belongs to the 1st main thread.

So bottom line - Yes you could run more than one application on the same JVM, but it would be awkward. I would use different JVMs for different apps. It "feels" more natural to the way the JVM is made.


Don't be shy, be quiet!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Azriel's answer is good. You could have a launcher that runs the main of any other class you tell it, so it could launch what you'd consider multiple applications.

And the other part of Mathew's question is good, too ... would they share objects in memory? The answer there is "yes" which is either a good thing because it lets them exchange data or a bad thing because each one clobbers data the other one is using. I wouldn't try it unless the two "applications" were very carefully written to work in such an environment.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://aspose.com/file-tools
subject: JVM
It's not a secret anymore!