• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Doubt Regarding JVM

 
Pavan Chillara
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pavan Chillara
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Launcher.java 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Bill
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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];
s[0]="A";
s[1]="C";
SubTest.main(s);
MyInterface.main(s);
System.out.println("Subtest Called");
MultipleMains.main(s);
}
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?

Regards,
Pavan
[ October 12, 2006: Message edited by: Pavan Chillara ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic