1
1
/*
2
- * Copyright (c) 1995, 2013 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1995, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -67,38 +67,32 @@ private Runtime() {}
67
67
* serves as a status code; by convention, a nonzero status code indicates
68
68
* abnormal termination.
69
69
*
70
- * <p> The virtual machine's shutdown sequence consists of two phases. In
71
- * the first phase all registered {@link #addShutdownHook shutdown hooks},
72
- * if any, are started in some unspecified order and allowed to run
73
- * concurrently until they finish. In the second phase all uninvoked
74
- * finalizers are run if {@link #runFinalizersOnExit finalization-on-exit}
75
- * has been enabled. Once this is done the virtual machine {@link #halt
76
- * halts}.
77
- *
78
- * <p> If this method is invoked after the virtual machine has begun its
79
- * shutdown sequence then if shutdown hooks are being run this method will
80
- * block indefinitely. If shutdown hooks have already been run and on-exit
81
- * finalization has been enabled then this method halts the virtual machine
82
- * with the given status code if the status is nonzero; otherwise, it
70
+ * <p> All registered {@linkplain #addShutdownHook shutdown hooks}, if any,
71
+ * are started in some unspecified order and allowed to run concurrently
72
+ * until they finish. Once this is done the virtual machine
73
+ * {@linkplain #halt halts}.
74
+ *
75
+ * <p> If this method is invoked after all shutdown hooks have already
76
+ * been run and the status is nonzero then this method halts the
77
+ * virtual machine with the given status code. Otherwise, this method
83
78
* blocks indefinitely.
84
79
*
85
- * <p> The <tt> {@link System#exit(int) System.exit}</tt> method is the
86
- * conventional and convenient means of invoking this method. <p>
80
+ * <p> The {@link System#exit(int) System.exit} method is the
81
+ * conventional and convenient means of invoking this method.
87
82
*
88
83
* @param status
89
84
* Termination status. By convention, a nonzero status code
90
85
* indicates abnormal termination.
91
86
*
92
87
* @throws SecurityException
93
- * If a security manager is present and its <tt>{@link
94
- * SecurityManager#checkExit checkExit}</tt> method does not permit
88
+ * If a security manager is present and its
89
+ * {@link SecurityManager#checkExit checkExit} method does not permit
95
90
* exiting with the specified status
96
91
*
97
92
* @see java.lang.SecurityException
98
93
* @see java.lang.SecurityManager#checkExit(int)
99
94
* @see #addShutdownHook
100
95
* @see #removeShutdownHook
101
- * @see #runFinalizersOnExit
102
96
* @see #halt(int)
103
97
*/
104
98
public void exit (int status ) {
@@ -118,11 +112,11 @@ public void exit(int status) {
118
112
* <ul>
119
113
*
120
114
* <li> The program <i>exits</i> normally, when the last non-daemon
121
- * thread exits or when the <tt> {@link #exit exit}</tt> (equivalently,
115
+ * thread exits or when the {@link #exit exit} (equivalently,
122
116
* {@link System#exit(int) System.exit}) method is invoked, or
123
117
*
124
118
* <li> The virtual machine is <i>terminated</i> in response to a
125
- * user interrupt, such as typing <tt>^C</tt> , or a system-wide event,
119
+ * user interrupt, such as typing {@code ^C} , or a system-wide event,
126
120
* such as user logoff or system shutdown.
127
121
*
128
122
* </ul>
@@ -131,20 +125,18 @@ public void exit(int status) {
131
125
* thread. When the virtual machine begins its shutdown sequence it will
132
126
* start all registered shutdown hooks in some unspecified order and let
133
127
* them run concurrently. When all the hooks have finished it will then
134
- * run all uninvoked finalizers if finalization-on-exit has been enabled.
135
- * Finally, the virtual machine will halt. Note that daemon threads will
136
- * continue to run during the shutdown sequence, as will non-daemon threads
137
- * if shutdown was initiated by invoking the <tt>{@link #exit exit}</tt>
138
- * method.
128
+ * halt. Note that daemon threads will continue to run during the shutdown
129
+ * sequence, as will non-daemon threads if shutdown was initiated by
130
+ * invoking the {@link #exit exit} method.
139
131
*
140
132
* <p> Once the shutdown sequence has begun it can be stopped only by
141
- * invoking the <tt> {@link #halt halt}</tt> method, which forcibly
133
+ * invoking the {@link #halt halt} method, which forcibly
142
134
* terminates the virtual machine.
143
135
*
144
136
* <p> Once the shutdown sequence has begun it is impossible to register a
145
137
* new shutdown hook or de-register a previously-registered hook.
146
138
* Attempting either of these operations will cause an
147
- * <tt> {@link IllegalStateException}</tt> to be thrown.
139
+ * {@link IllegalStateException} to be thrown.
148
140
*
149
141
* <p> Shutdown hooks run at a delicate time in the life cycle of a virtual
150
142
* machine and should therefore be coded defensively. They should, in
@@ -156,7 +148,7 @@ public void exit(int status) {
156
148
* deadlocks.
157
149
*
158
150
* <p> Shutdown hooks should also finish their work quickly. When a
159
- * program invokes <tt> {@link #exit exit}</tt> the expectation is
151
+ * program invokes {@link #exit exit} the expectation is
160
152
* that the virtual machine will promptly shut down and exit. When the
161
153
* virtual machine is terminated due to user logoff or system shutdown the
162
154
* underlying operating system may only allow a fixed amount of time in
@@ -165,25 +157,25 @@ public void exit(int status) {
165
157
* hook.
166
158
*
167
159
* <p> Uncaught exceptions are handled in shutdown hooks just as in any
168
- * other thread, by invoking the <tt>{@link ThreadGroup#uncaughtException
169
- * uncaughtException}</tt> method of the thread's <tt>{@link
170
- * ThreadGroup}</tt> object. The default implementation of this method
171
- * prints the exception's stack trace to <tt> {@link System#err}</tt> and
160
+ * other thread, by invoking the
161
+ * {@link ThreadGroup# uncaughtException uncaughtException} method of the
162
+ * thread's {@link ThreadGroup} object. The default implementation of this
163
+ * method prints the exception's stack trace to {@link System#err} and
172
164
* terminates the thread; it does not cause the virtual machine to exit or
173
165
* halt.
174
166
*
175
167
* <p> In rare circumstances the virtual machine may <i>abort</i>, that is,
176
168
* stop running without shutting down cleanly. This occurs when the
177
169
* virtual machine is terminated externally, for example with the
178
- * <tt> SIGKILL</tt> signal on Unix or the <tt> TerminateProcess</tt> call on
170
+ * {@code SIGKILL} signal on Unix or the {@code TerminateProcess} call on
179
171
* Microsoft Windows. The virtual machine may also abort if a native
180
172
* method goes awry by, for example, corrupting internal data structures or
181
173
* attempting to access nonexistent memory. If the virtual machine aborts
182
174
* then no guarantee can be made about whether or not any shutdown hooks
183
- * will be run. <p>
175
+ * will be run.
184
176
*
185
177
* @param hook
186
- * An initialized but unstarted <tt> {@link Thread}</tt> object
178
+ * An initialized but unstarted {@link Thread} object
187
179
*
188
180
* @throws IllegalArgumentException
189
181
* If the specified hook has already been registered,
@@ -196,7 +188,7 @@ public void exit(int status) {
196
188
*
197
189
* @throws SecurityException
198
190
* If a security manager is present and it denies
199
- * <tt> {@link RuntimePermission}("shutdownHooks")</tt>
191
+ * {@link RuntimePermission}{@code ("shutdownHooks")}
200
192
*
201
193
* @see #removeShutdownHook
202
194
* @see #halt(int)
@@ -244,23 +236,22 @@ public boolean removeShutdownHook(Thread hook) {
244
236
* method never returns normally.
245
237
*
246
238
* <p> This method should be used with extreme caution. Unlike the
247
- * <tt>{@link #exit exit}</tt> method, this method does not cause shutdown
248
- * hooks to be started and does not run uninvoked finalizers if
249
- * finalization-on-exit has been enabled. If the shutdown sequence has
250
- * already been initiated then this method does not wait for any running
251
- * shutdown hooks or finalizers to finish their work. <p>
239
+ * {@link #exit exit} method, this method does not cause shutdown
240
+ * hooks to be started. If the shutdown sequence has already been
241
+ * initiated then this method does not wait for any running
242
+ * shutdown hooks to finish their work.
252
243
*
253
244
* @param status
254
- * Termination status. By convention, a nonzero status code
255
- * indicates abnormal termination. If the <tt> {@link Runtime#exit
256
- * exit}</tt> (equivalently, <tt> {@link System#exit(int)
257
- * System.exit}</tt>) method has already been invoked then this
258
- * status code will override the status code passed to that method.
245
+ * Termination status. By convention, a nonzero status code
246
+ * indicates abnormal termination. If the {@link Runtime#exit exit}
247
+ * (equivalently, {@link System#exit(int) System.exit}) method
248
+ * has already been invoked then this status code
249
+ * will override the status code passed to that method.
259
250
*
260
251
* @throws SecurityException
261
- * If a security manager is present and its <tt>{@link
262
- * SecurityManager#checkExit checkExit}</tt> method does not permit
263
- * an exit with the specified status
252
+ * If a security manager is present and its
253
+ * {@link SecurityManager#checkExit checkExit} method
254
+ * does not permit an exit with the specified status
264
255
*
265
256
* @see #exit
266
257
* @see #addShutdownHook
@@ -277,42 +268,23 @@ public void halt(int status) {
277
268
}
278
269
279
270
/**
280
- * Enable or disable finalization on exit; doing so specifies that the
281
- * finalizers of all objects that have finalizers that have not yet been
282
- * automatically invoked are to be run before the Java runtime exits.
283
- * By default, finalization on exit is disabled.
284
- *
285
- * <p>If there is a security manager,
286
- * its <code>checkExit</code> method is first called
287
- * with 0 as its argument to ensure the exit is allowed.
288
- * This could result in a SecurityException.
289
- *
290
- * @param value true to enable finalization on exit, false to disable
291
- * @deprecated This method is inherently unsafe. It may result in
292
- * finalizers being called on live objects while other threads are
293
- * concurrently manipulating those objects, resulting in erratic
294
- * behavior or deadlock.
271
+ * Throws {@code UnsupportedOperationException}.
295
272
*
296
- * @throws SecurityException
297
- * if a security manager exists and its <code>checkExit</code>
298
- * method doesn't allow the exit.
273
+ * @param value ignored
299
274
*
300
- * @see java.lang.Runtime#exit(int)
301
- * @see java.lang.Runtime#gc()
302
- * @see java.lang.SecurityManager#checkExit(int)
303
- * @since JDK1.1
275
+ * @deprecated This method was originally designed to enable or disable
276
+ * running finalizers on exit. Running finalizers on exit was disabled by default.
277
+ * If enabled, then the finalizers of all objects whose finalizers had not
278
+ * yet been automatically invoked were to be run before the Java runtime exits.
279
+ * That behavior is inherently unsafe. It may result in finalizers being called
280
+ * on live objects while other threads are concurrently manipulating those objects,
281
+ * resulting in erratic behavior or deadlock.
282
+ *
283
+ * @since JDK1.1
304
284
*/
305
285
@ Deprecated
306
286
public static void runFinalizersOnExit (boolean value ) {
307
- SecurityManager security = System .getSecurityManager ();
308
- if (security != null ) {
309
- try {
310
- security .checkExit (0 );
311
- } catch (SecurityException e ) {
312
- throw new SecurityException ("runFinalizersOnExit" );
313
- }
314
- }
315
- Shutdown .setRunFinalizersOnExit (value );
287
+ throw new UnsupportedOperationException ();
316
288
}
317
289
318
290
/**
0 commit comments