Don't call System.exit() from shutdown hook thread
This commit is contained in:
parent
8b6fe63df1
commit
728961d19f
@ -52,7 +52,7 @@ public abstract class CLIApplication {
|
|||||||
new CommandAdmin();
|
new CommandAdmin();
|
||||||
new CommandStop();
|
new CommandStop();
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
|
Runtime.getRuntime().addShutdownHook(shutdownThread);
|
||||||
|
|
||||||
cli.start(); // actually starts the CLI thread
|
cli.start(); // actually starts the CLI thread
|
||||||
|
|
||||||
@ -71,12 +71,13 @@ public abstract class CLIApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final Thread shutdownThread = new Thread(this::stop);
|
||||||
|
|
||||||
private final AtomicBoolean stopping = new AtomicBoolean(false);
|
private final AtomicBoolean stopping = new AtomicBoolean(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops this application.
|
* Stops this application.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("finally")
|
|
||||||
public final void stop() {
|
public final void stop() {
|
||||||
synchronized (stopping) {
|
synchronized (stopping) {
|
||||||
if (stopping.get())
|
if (stopping.get())
|
||||||
@ -88,10 +89,10 @@ public abstract class CLIApplication {
|
|||||||
end();
|
end();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Log.severe("Error stopping application " + getName() + " version " + getClass().getPackage().getImplementationVersion(), t);
|
Log.severe("Error stopping application " + getName() + " version " + getClass().getPackage().getImplementationVersion(), t);
|
||||||
System.exit(1);
|
|
||||||
} finally {
|
} finally {
|
||||||
Log.info("Bye bye.");
|
Log.info("Bye bye.");
|
||||||
System.exit(0);
|
if (!Thread.currentThread().equals(shutdownThread))
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user