aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is There different VM for every Java program? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Is There different VM for every Java program?" Watch "Is There different VM for every Java program?" New topic
Author

Is There different VM for every Java program?

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317


In K&B on page 336

table 5-1 Causes of Early Loop Termination

states that

System.exit() - All program execution stops; the VM shuts down.

Means if we execute the statement System.exit(). System will terminate the program and shuts down the VM. Is this means that for every program there is different VM. As per my understanding there is only one VM and every program will be executed under this VM.

I am confused. Please help me to get it clarify.
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

When you execute the java command, a new JVM instance is started and your program executes in that JVM. Calling System.exit() will shut down a particular JVM. The JVM may contain multiple threads i.e. the main thread in which the main method is called and any other threads that we start (and some internal threads like garbage collector etc). All these threads end when the JVM is shut down...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Do you mean that there will be a single VM and each program will be executed under the sub VM's which is again under that main VM?
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

Each program executes in its separate VM. We run programs using java command. The java command launches a new VM. In the same program if we start a new thread, the thread will be in the same VM in which the original program was started. So basically whenever you run your program using java <MainClassName>, then a new VM is started...
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Thank you Ankit for the explanation
Jeevan Reddy
Ranch Hand

Joined: Nov 10, 2009
Posts: 142
Thanks Ankit for the clarification.


SCJP 1.6 (94%)
http://faq.javaranch.com/java/JspFaq
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is There different VM for every Java program?
 
Similar Threads
what will happen if i do not write the main function in my program???
why the prm continue executing after I put "response.sendRedirect()" ?
finally blocks (with respect to JVM Shutdown vs System.exit(0))
javaw.exe -jar = doesn't work BUT java.exe -jar = works ?
tomcat keeping shuting down