Hi, 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. Thx. Mathew
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.<br /> <br />#:^P
Joined: Nov 27, 2001
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
Joined: Jan 31, 2005
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
Joined: Dec 10, 2003
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.
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!
Joined: Jan 29, 2003
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