Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM

 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Azriel Abramovich
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


A'z
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic