| 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
|
|
|
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
|
|
|
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
|
 |
 |
|
|
subject: Is There different VM for every Java program?
|
|
|