Code for terminating Virtual Machines




public class TerminateVirtualMachine {
     
        public static void main(String args[])
        {
                /*
                 * get current Java Runtime using getRuntime()
                 * method of Runtime class.
                 */
                Runtime runtime = Runtime.getRuntime();
             
                /*
                 * To forcibly terminate the currently running virtual machine, use
                 *
                 * void halt(int status)
                 * method of Runtime class.
                 *
                 * Usually, non-zero status is passed as status for abnormal exit.
                 *
                 * Please note that, unlike exit method, this method DOES NOT invoke
                 * shutdown hooks or run object finalizers.
                 *
                 *
                 */
               
                 System.out.println("About to halt the current jvm");
             
               
                 /*
                  * THIS METHOD NEVER RETURNS NORMALLY.
                  * This statement will never executed, as the JVM is
                  * terminated!
                  */
                 System.out.println("JVM Terminated");
                 runtime.halt(0);
        }
     
}

/*
Typical output would be
About to halt the current jvm
*/

Post a Comment

0 Comments

Recent in Recipes

3/Food/post-list