Skip to content

Commit 95cdbb2

Browse files
committed
don't show "shutdown(0)" twice
1 parent 78260e5 commit 95cdbb2

File tree

2 files changed

+49
-44
lines changed

2 files changed

+49
-44
lines changed

sources/net.sf.j2s.java.core/src/java/lang/Runtime.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -245,41 +245,41 @@ public boolean removeShutdownHook(Thread hook) {
245245
return ApplicationShutdownHooks.remove(hook);
246246
}
247247

248-
/**
249-
* Forcibly terminates the currently running Java virtual machine. This
250-
* method never returns normally.
251-
*
252-
* <p> This method should be used with extreme caution. Unlike the
253-
* <tt>{@link #exit exit}</tt> method, this method does not cause shutdown
254-
* hooks to be started and does not run uninvoked finalizers if
255-
* finalization-on-exit has been enabled. If the shutdown sequence has
256-
* already been initiated then this method does not wait for any running
257-
* shutdown hooks or finalizers to finish their work. <p>
258-
*
259-
* @param status
260-
* Termination status. By convention, a nonzero status code
261-
* indicates abnormal termination. If the <tt>{@link Runtime#exit
262-
* exit}</tt> (equivalently, <tt>{@link System#exit(int)
263-
* System.exit}</tt>) method has already been invoked then this
264-
* status code will override the status code passed to that method.
265-
*
266-
* @throws SecurityException
267-
* If a security manager is present and its <tt>{@link
268-
* SecurityManager#checkExit checkExit}</tt> method does not permit
269-
* an exit with the specified status
270-
*
271-
* @see #exit
272-
* @see #addShutdownHook
273-
* @see #removeShutdownHook
274-
* @since 1.3
275-
*/
276-
public void halt(int status) {
277-
SecurityManager sm = System.getSecurityManager();
278-
if (sm != null) {
279-
sm.checkExit(status);
280-
}
281-
Shutdown.halt(status);
282-
}
248+
/**
249+
* Forcibly terminates the currently running Java virtual machine. This method
250+
* never returns normally.
251+
*
252+
* <p>
253+
* This method should be used with extreme caution. Unlike the
254+
* <tt>{@link #exit exit}</tt> method, this method does not cause shutdown hooks
255+
* to be started and does not run uninvoked finalizers if finalization-on-exit
256+
* has been enabled. If the shutdown sequence has already been initiated then
257+
* this method does not wait for any running shutdown hooks or finalizers to
258+
* finish their work.
259+
* <p>
260+
*
261+
* @param status Termination status. By convention, a nonzero status code
262+
* indicates abnormal termination. If the <tt>{@link Runtime#exit
263+
* exit}</tt> (equivalently, <tt>{@link System#exit(int)
264+
* System.exit}</tt>) method has already been invoked then this status
265+
* code will override the status code passed to that method.
266+
*
267+
* @throws SecurityException If a security manager is present and its <tt>{@link
268+
* SecurityManager#checkExit checkExit}</tt> method does not permit an
269+
* exit with the specified status
270+
*
271+
* @see #exit
272+
* @see #addShutdownHook
273+
* @see #removeShutdownHook
274+
* @since 1.3
275+
*/
276+
public void halt(int status) {
277+
SecurityManager sm = System.getSecurityManager();
278+
if (sm != null) {
279+
sm.checkExit(status);
280+
}
281+
Shutdown.halt(status);
282+
}
283283

284284
/**
285285
* Enable or disable finalization on exit; doing so specifies that the

sources/net.sf.j2s.java.core/src/java/lang/Shutdown.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Shutdown {
6767

6868
/* Lock object for the native halt method */
6969
private static Object haltLock = null;//new Lock();
70+
private static boolean 秘isHalted;
7071

7172
/* Invoked by Runtime.runFinalizersOnExit */
7273
static void setRunFinalizersOnExit(boolean run) {
@@ -158,16 +159,20 @@ private static void runHooks() {
158159
}
159160
}
160161

161-
/* The halt method is synchronized on the halt lock
162-
* to avoid corruption of the delete-on-shutdown file list.
163-
* It invokes the true native halt method.
164-
*/
165-
static void halt(int status) {
166-
synchronized (haltLock) {
167-
System.out.println("Shutdown(" + status + ") on " + Thread.currentThread().getThreadGroup().getName());
162+
/*
163+
* The halt method is synchronized on the halt lock to avoid corruption of the
164+
* delete-on-shutdown file list. It invokes the true native halt method.
165+
*/
166+
static void halt(int status) {
167+
synchronized (haltLock) {
168+
169+
if (!秘isHalted) {
170+
秘isHalted = true;
171+
System.out.println("Shutdown(" + status + ") on " + Thread.currentThread().getThreadGroup().getName());
168172
// halt0(status);
169-
}
170-
}
173+
}
174+
}
175+
}
171176

172177
// static native void halt0(int status);
173178

0 commit comments

Comments
 (0)