📄 runtime.html
字号:
<TD><CODE><B><A HREF="../../java/lang/Runtime.html#runFinalization()">runFinalization</A></B>()</CODE><BR> Runs the finalization methods of any objects pending finalization.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/lang/Runtime.html#runFinalizersOnExit(boolean)">runFinalizersOnExit</A></B>(boolean value)</CODE><BR> <B>Deprecated.</B> <I>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.</I></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> long</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/lang/Runtime.html#totalMemory()">totalMemory</A></B>()</CODE><BR> Returns the total amount of memory in the Java Virtual Machine.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/lang/Runtime.html#traceInstructions(boolean)">traceInstructions</A></B>(boolean on)</CODE><BR> Enables/Disables tracing of instructions.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/lang/Runtime.html#traceMethodCalls(boolean)">traceMethodCalls</A></B>(boolean on)</CODE><BR> Enables/Disables tracing of method calls.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html">Object</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../java/lang/Object.html#clone()">clone</A>, <A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/lang/Object.html#finalize()">finalize</A>, <A HREF="../../java/lang/Object.html#getClass()">getClass</A>, <A HREF="../../java/lang/Object.html#hashCode()">hashCode</A>, <A HREF="../../java/lang/Object.html#notify()">notify</A>, <A HREF="../../java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../java/lang/Object.html#toString()">toString</A>, <A HREF="../../java/lang/Object.html#wait()">wait</A>, <A HREF="../../java/lang/Object.html#wait(long)">wait</A>, <A HREF="../../java/lang/Object.html#wait(long, int)">wait</A></CODE></TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="getRuntime()"><!-- --></A><H3>getRuntime</H3><PRE>public static <A HREF="../../java/lang/Runtime.html">Runtime</A> <B>getRuntime</B>()</PRE><DL><DD>Returns the runtime object associated with the current Java application. Most of the methods of class <code>Runtime</code> are instance methods and must be invoked with respect to the current runtime object.<DD><DL><DT><B>Returns:</B><DD>the <code>Runtime</code> object associated with the current Java application.</DL></DD></DL><HR><A NAME="exit(int)"><!-- --></A><H3>exit</H3><PRE>public void <B>exit</B>(int status)</PRE><DL><DD>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 constists of two phases. In the first phase all registered <A HREF="../../java/lang/Runtime.html#addShutdownHook(java.lang.Thread)"><CODE>shutdown hooks</CODE></A>, 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 <A HREF="../../java/lang/Runtime.html#runFinalizersOnExit(boolean)"><CODE>finalization-on-exit</CODE></A> has been enabled. Once this is done the virtual machine <A HREF="../../java/lang/Runtime.html#halt(int)"><CODE>halts</CODE></A>. <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 <tt><A HREF="../../java/lang/System.html#exit(int)"><CODE>System.exit</CODE></A></tt> method is the conventional and convenient means of invoking this method. <p><DD><DL><DT><B>Parameters:</B><DD><CODE>status</CODE> - Termination status. By convention, a nonzero status code indicates abnormal termination.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - If a security manager is present and its <tt><A HREF="../../java/lang/SecurityManager.html#checkExit(int)"><CODE>checkExit</CODE></A></tt> method does not permit exiting with the specified status<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityException.html"><CODE>SecurityException</CODE></A>, <A HREF="../../java/lang/SecurityManager.html#checkExit(int)"><CODE>SecurityManager.checkExit(int)</CODE></A>, <A HREF="../../java/lang/Runtime.html#addShutdownHook(java.lang.Thread)"><CODE>addShutdownHook(java.lang.Thread)</CODE></A>, <A HREF="../../java/lang/Runtime.html#removeShutdownHook(java.lang.Thread)"><CODE>removeShutdownHook(java.lang.Thread)</CODE></A>, <A HREF="../../java/lang/Runtime.html#runFinalizersOnExit(boolean)"><CODE>runFinalizersOnExit(boolean)</CODE></A>, <A HREF="../../java/lang/Runtime.html#halt(int)"><CODE>halt(int)</CODE></A></DL></DD></DL><HR><A NAME="addShutdownHook(java.lang.Thread)"><!-- --></A><H3>addShutdownHook</H3><PRE>public void <B>addShutdownHook</B>(<A HREF="../../java/lang/Thread.html">Thread</A> hook)</PRE><DL><DD>Registers a new virtual-machine shutdown hook. <p> The Java virtual machine <i>shuts down</i> in response to two kinds of events: <ul> <p> <li> The program <i>exits</i> normally, when the last non-daemon thread exits or when the <tt><A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit</CODE></A></tt> (equivalently, <tt><A HREF="../../java/lang/System.html#exit(int)"><CODE>System.exit</CODE></A></tt>) method is invoked, or <p> <li> The virtual machine is <i>terminated</i> in response to a user interrupt, such as typing <tt>^C</tt>, or a system-wide event, such as user logoff or system shutdown. </ul> <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 <tt><A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit</CODE></A></tt> method. <p> Once the shutdown sequence has begun it can be stopped only by invoking the <tt><A HREF="../../java/lang/Runtime.html#halt(int)"><CODE>halt</CODE></A></tt> method, which forcibly terminates the virtual machine. <p> Once the shutdown sequence has begun it is impossible to register a new shutdown hook or de-register a previously-registered hook. Attempting either of these operations will cause an <tt><A HREF="../../java/lang/IllegalStateException.html"><CODE>IllegalStateException</CODE></A></tt> to be thrown. <p> Shutdown hooks run at a delicate time in the life cycle of a virtual machine and should therefore be coded defensively. They should, in particular, be written to be thread-safe and to avoid deadlocks insofar as possible. They should also not rely blindly upon services that may have registered their own shutdown hooks and therefore may themselves in the process of shutting down. <p> Shutdown hooks should also finish their work quickly. When a program invokes <tt><A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit</CODE></A></tt> the expectation is that the virtual machine will promptly shut down and exit. When the virtual machine is terminated due to user logoff or system shutdown the underlying operating system may only allow a fixed amount of time in which to shut down and exit. It is therefore inadvisable to attempt any user interaction or to perform a long-running computation in a shutdown hook. <p> Uncaught exceptions are handled in shutdown hooks just as in any other thread, by invoking the <tt><A HREF="../../java/lang/ThreadGroup.html#uncaughtException(java.lang.Thread, java.lang.Throwable)"><CODE>uncaughtException</CODE></A></tt> method of the thread's <tt><A HREF="../../java/lang/ThreadGroup.html"><CODE>ThreadGroup</CODE></A></tt> object. The default implementation of this method prints the exception's stack trace to <tt><A HREF="../../java/lang/System.html#err"><CODE>System.err</CODE></A></tt> and terminates the thread; it does not cause the virtual machine to exit or halt. <p> In rare circumstances the virtual machine may <i>abort</i>, that is, stop running without shutting down cleanly. This occurs when the virtual machine is terminated externally, for example with the <tt>SIGKILL</tt> signal on Unix or the <tt>TerminateProcess</tt> call on Win32. The virtual machine may also abort if a native method goes awry by, for example, corrupting internal data structures or attempting to access nonexistent memory. If the virtual machine aborts then no guarantee can be made about whether or not any shutdown hooks will be run. <p><DD><DL><DT><B>Parameters:</B><DD><CODE>hook</CODE> - An initialized but unstarted <tt><A HREF="../../java/lang/Thread.html"><CODE>Thread</CODE></A></tt> object<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - If the specified hook has already been registered, or if it can be determined that the hook is already running or has already been run<DD><CODE><A HREF="../../java/lang/IllegalStateException.html">IllegalStateException</A></CODE> - If the virtual machine is already in the process of shutting down<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - If a security manager is present and it denies <tt><A HREF="../../java/lang/RuntimePermission.html"><CODE>RuntimePermission</CODE></A>("shutdownHooks")</tt><DT><B>Since: </B><DD>1.3</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/Runtime.html#removeShutdownHook(java.lang.Thread)"><CODE>removeShutdownHook(java.lang.Thread)</CODE></A>, <A HREF="../../java/lang/Runtime.html#halt(int)"><CODE>halt(int)</CODE></A>, <A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit(int)</CODE></A></DL></DD></DL><HR><A NAME="removeShutdownHook(java.lang.Thread)"><!-- --></A><H3>removeShutdownHook</H3><PRE>public boolean <B>removeShutdownHook</B>(<A HREF="../../java/lang/Thread.html">Thread</A> hook)</PRE><DL><DD>De-registers a previously-registered virtual-machine shutdown hook. <p><DD><DL><DT><B>Parameters:</B><DD><CODE>hook</CODE> - the hook to remove<DT><B>Returns:</B><DD><tt>true</tt> if the specified hook had previously been registered and was successfully de-registered, <tt>false</tt> otherwise.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/IllegalStateException.html">IllegalStateException</A></CODE> - If the virtual machine is already in the process of shutting down<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - If a security manager is present and it denies <tt><A HREF="../../java/lang/RuntimePermission.html"><CODE>RuntimePermission</CODE></A>("shutdownHooks")</tt><DT><B>Since: </B><DD>1.3</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/Runtime.html#addShutdownHook(java.lang.Thread)"><CODE>addShutdownHook(java.lang.Thread)</CODE></A>, <A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit(int)</CODE></A></DL></DD></DL><HR><A NAME="halt(int)"><!-- --></A><H3>halt</H3><PRE>public void <B>halt</B>(int status)</PRE><DL><DD>Forcibly terminates the currently running Java virtual machine. This method never returns normally. <p> This method should be used with extreme caution. Unlike the <tt><A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit</CODE></A></tt> 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. <p><DD><DL><DT><B>Parameters:</B><DD><CODE>status</CODE> - Termination status. By convention, a nonzero status code indicates abnormal termination. If the <tt><A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit</CODE></A></tt> (equivalently, <tt><A HREF="../../java/lang/System.html#exit(int)"><CODE>System.exit</CODE></A></tt>) method has already been invoked then this status code will override the status code passed to that method.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - If a security manager is present and its <tt><A HREF="../../java/lang/SecurityManager.html#checkExit(int)"><CODE>checkExit</CODE></A></tt> method does not permit an exit with the specified status<DT><B>Since: </B><DD>1.3</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/Runtime.html#exit(int)"><CODE>exit(int)</CODE></A>, <A HREF="../../java/lang/Runtime.html#addShutdownHook(java.lang.Thread)"><CODE>addShutdownHook(java.lang.Thread)</CODE></A>, <A HREF="../../java/lang/Runtime.html#removeShutdownHook(java.lang.Thread)"><CODE>removeShutdownHook(java.lang.Thread)</CODE></A></DL></DD></DL><HR><A NAME="runFinalizersOnExit(boolean)"><!-- --></A><H3>runFinalizersOnExit</H3><PRE>public static void <B>runFinalizersOnExit</B>(boolean value)</PRE><DL><DD><B>Deprecated.</B> <I>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.</I>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -