< prev index next >

src/java.base/share/classes/java/lang/Runtime.java

Print this page

        

*** 33,42 **** --- 33,44 ---- import java.util.stream.Collectors; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.StringTokenizer; + + import jdk.internal.misc.SharedSecrets; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; /** * Every Java application has a single instance of class
*** 75,97 **** * Terminates the currently running Java virtual machine by initiating its * shutdown sequence. This method never returns normally. The argument * serves as a status code; by convention, a nonzero status code indicates * abnormal termination. * ! * <p> The virtual machine's shutdown sequence consists of two phases. In ! * the first phase all registered {@link #addShutdownHook shutdown hooks}, ! * if any, are started in some unspecified order and allowed to run ! * concurrently until they finish. In the second phase all uninvoked ! * finalizers are run if {@link #runFinalizersOnExit finalization-on-exit} ! * has been enabled. Once this is done the virtual machine {@link #halt halts}. ! * ! * <p> If this method is invoked after the virtual machine has begun its ! * shutdown sequence then if shutdown hooks are being run this method will ! * block indefinitely. If shutdown hooks have already been run and on-exit ! * finalization has been enabled then this method halts the virtual machine ! * with the given status code if the status is nonzero; otherwise, it ! * blocks indefinitely. * * <p> The {@link System#exit(int) System.exit} method is the * conventional and convenient means of invoking this method. * * @param status --- 77,97 ---- * Terminates the currently running Java virtual machine by initiating its * shutdown sequence. This method never returns normally. The argument * serves as a status code; by convention, a nonzero status code indicates * abnormal termination. * ! * <p> All registered {@link #addShutdownHook shutdown hooks}, if any, ! * are started in some unspecified order and allowed to run concurrently ! * until they finish. Once this is done the virtual machine ! * {@link #halt halts}. ! * ! * <p> If this method is invoked after the virtual machine has started ! * shutdown hooks then if shutdown hooks have already been run and ! * the status is nonzero then this method halts the virtual machine ! * with the given status code; otherwise, this method blocks indefinitely ! * (i.e. if shutdown hooks are being run or if shutdown hooks have already ! * been run and the status is zero). * * <p> The {@link System#exit(int) System.exit} method is the * conventional and convenient means of invoking this method. * * @param status
*** 105,115 **** * * @see java.lang.SecurityException * @see java.lang.SecurityManager#checkExit(int) * @see #addShutdownHook * @see #removeShutdownHook - * @see #runFinalizersOnExit * @see #halt(int) */ public void exit(int status) { SecurityManager security = System.getSecurityManager(); if (security != null) { --- 105,114 ----
*** 138,151 **** * * <p> A <i>shutdown hook</i> is simply an initialized but unstarted * thread. When the virtual machine begins its shutdown sequence it will * start all registered shutdown hooks in some unspecified order and let * them run concurrently. When all the hooks have finished it will then ! * run all uninvoked finalizers if finalization-on-exit has been enabled. ! * Finally, the virtual machine will halt. Note that daemon threads will ! * continue to run during the shutdown sequence, as will non-daemon threads ! * if shutdown was initiated by invoking the {@link #exit exit} method. * * <p> Once the shutdown sequence has begun it can be stopped only by * invoking the {@link #halt halt} method, which forcibly * terminates the virtual machine. * --- 137,149 ---- * * <p> A <i>shutdown hook</i> is simply an initialized but unstarted * thread. When the virtual machine begins its shutdown sequence it will * start all registered shutdown hooks in some unspecified order and let * them run concurrently. When all the hooks have finished it will then ! * halt. Note that daemon threads will continue to run during the shutdown ! * sequence, as will non-daemon threads if shutdown was initiated by ! * invoking the {@link #exit exit} method. * * <p> Once the shutdown sequence has begun it can be stopped only by * invoking the {@link #halt halt} method, which forcibly * terminates the virtual machine. *
*** 251,264 **** * Forcibly terminates the currently running Java virtual machine. This * method never returns normally. * * <p> This method should be used with extreme caution. Unlike the * {@link #exit exit} method, this method does not cause shutdown ! * hooks to be started and does not run uninvoked finalizers if ! * finalization-on-exit has been enabled. If the shutdown sequence has ! * already been initiated then this method does not wait for any running ! * shutdown hooks or finalizers to finish their work. * * @param status * Termination status. By convention, a nonzero status code * indicates abnormal termination. If the {@link Runtime#exit exit} * (equivalently, {@link System#exit(int) System.exit}) method --- 249,261 ---- * Forcibly terminates the currently running Java virtual machine. This * method never returns normally. * * <p> This method should be used with extreme caution. Unlike the * {@link #exit exit} method, this method does not cause shutdown ! * hooks to be started. If the shutdown sequence has already been ! * initiated then this method does not wait for any running ! * shutdown hooks to finish their work. * * @param status * Termination status. By convention, a nonzero status code * indicates abnormal termination. If the {@link Runtime#exit exit} * (equivalently, {@link System#exit(int) System.exit}) method
*** 282,331 **** } Shutdown.halt(status); } /** - * Enable or disable finalization on exit; doing so specifies that the - * finalizers of all objects that have finalizers that have not yet been - * automatically invoked are to be run before the Java runtime exits. - * By default, finalization on exit is disabled. - * - * <p>If there is a security manager, - * its {@code checkExit} method is first called - * with 0 as its argument to ensure the exit is allowed. - * This could result in a SecurityException. - * - * @param value true to enable finalization on exit, false to disable - * @deprecated This method is inherently unsafe. It may result in - * finalizers being called on live objects while other threads are - * concurrently manipulating those objects, resulting in erratic - * behavior or deadlock. - * This method is subject to removal in a future version of Java SE. - * - * @throws SecurityException - * if a security manager exists and its {@code checkExit} - * method doesn't allow the exit. - * - * @see java.lang.Runtime#exit(int) - * @see java.lang.Runtime#gc() - * @see java.lang.SecurityManager#checkExit(int) - * @since 1.1 - */ - @Deprecated(since="1.2", forRemoval=true) - public static void runFinalizersOnExit(boolean value) { - SecurityManager security = System.getSecurityManager(); - if (security != null) { - try { - security.checkExit(0); - } catch (SecurityException e) { - throw new SecurityException("runFinalizersOnExit"); - } - } - Shutdown.setRunFinalizersOnExit(value); - } - - /** * Executes the specified string command in a separate process. * * <p>This is a convenience method. An invocation of the form * {@code exec(command)} * behaves in exactly the same way as the invocation --- 279,288 ----
*** 700,712 **** * The method {@link System#gc()} is the conventional and convenient * means of invoking this method. */ public native void gc(); - /* Wormhole for calling java.lang.ref.Finalizer.runFinalization */ - private static native void runFinalization0(); - /** * Runs the finalization methods of any objects pending finalization. * Calling this method suggests that the Java virtual machine expend * effort toward running the {@code finalize} methods of objects * that have been found to be discarded but whose {@code finalize} --- 657,666 ----
*** 722,732 **** * and convenient means of invoking this method. * * @see java.lang.Object#finalize() */ public void runFinalization() { ! runFinalization0(); } /** * Not implemented, does nothing. * --- 676,686 ---- * and convenient means of invoking this method. * * @see java.lang.Object#finalize() */ public void runFinalization() { ! SharedSecrets.getJavaLangRefAccess().runFinalization(); } /** * Not implemented, does nothing. *
< prev index next >