File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Basic Doubt Regarding JVM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Basic Doubt Regarding JVM" Watch "Basic Doubt Regarding JVM" New topic

Basic Doubt Regarding JVM

Pavan Chillara

Joined: Sep 27, 2006
Posts: 14

I am beginner to Java and J2EE,
I have one doubt regarding JVM

Can one JVM be employed for running mutiple java programs,Why am i asking this Question means,As we know servletContainer, JSPContainer and EJB Container running in a server,Each of these container is a compliled and executed programme,So Server itself is holding all these programs simultaneously to handle requests with single JVM..How is it possible?
If any one clarifies this doubt i will be very thankful.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Well, it depends on your definition of "program". In the case of a Web server, I would say there is just one program - the Web server - which runs a whole load of Web applications. But that's just my take on it.

In fact, though, one JVM can be used to run a number of totally separate, unconnected applications. The "java" executable that is usually used to launch a Java program is not the only way to run Java code. Using the Java Invocation API, you can use native (typically C/C++) code to instantiate a JVM, load classes, start threads, run methods etc. You could write your own launcher program that ran as many separate Java applications as you liked.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Pavan Chillara

Joined: Sep 27, 2006
Posts: 14
Thank You Mr.Peter,

I got the answer for my question, here webserver itself is a program that runs multiple programs like servletContainer,JSPContainer,...etc and some otherthings.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Sounds like you got an answer to your particular question, but let's generalize it a bit. To run one "program" you usually say

which runs Program1.main(). There's nothing to prevent us from writing that does:

Now is it running three programs or one? That's the tricky bit about defining "program." They'll all share "global" resources in the JVM like memory space, static variables and connection pools and such. Is that good or bad? Depends on how the "programs" are designed.

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
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12671
here webserver itself is a program that runs multiple programs like

Don't think "program that runs multiple programs" - think program that oversees multiple Threads separately assigned to running subprograms as needed.

Making the jump from single-threaded desktop utilities to multi-thread applications takes some re-thinking of your mental picture of program internals.


Java Resources at
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Excellent clarification. I didn't show any threads happening in my little example. I will pretend I meant each main() started a new thread.
Pavan Chillara

Joined: Sep 27, 2006
Posts: 14
Thank You Mr. William Brogden and Stan James,

I have one more doubt here,I have written a java program like below

public static void main(String[] args)

String[] s=new String[2];
System.out.println("Subtest Called");
In the above code i have called 3 main() methods but only MultipleMains.main(s) is executed.The rest of the two main() methods are not executed,May i know the reason Why?Can anybody clarify my doubt?

[ October 12, 2006: Message edited by: Pavan Chillara ]
I agree. Here's the link:
subject: Basic Doubt Regarding JVM
Similar Threads
JVM doubt
GC doubt
A doubt with Singleton pattern
JVM Related Doubt