• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Basic Doubt Regarding JVM

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic