HADOOP-12423. Handle failure of registering shutdownhook by ShutdownHookManager in static block (Contributed by Abhishek Agarwal)

This commit is contained in:
Vinayakumar B 2016-01-21 20:08:24 +05:30
parent b7372b7166
commit 446987e20a
2 changed files with 21 additions and 13 deletions

View File

@ -1630,6 +1630,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-12356. Fix computing CPU usage statistics on Windows. HADOOP-12356. Fix computing CPU usage statistics on Windows.
(Inigo Goiri via wangda) (Inigo Goiri via wangda)
HADOOP-12423. Handle failure of registering shutdownhook by
ShutdownHookManager in static block (Abhishek Agarwal via vinayakumarb)
Release 2.7.3 - UNRELEASED Release 2.7.3 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -44,22 +44,27 @@ public class ShutdownHookManager {
private static final Log LOG = LogFactory.getLog(ShutdownHookManager.class); private static final Log LOG = LogFactory.getLog(ShutdownHookManager.class);
static { static {
Runtime.getRuntime().addShutdownHook( try {
new Thread() { Runtime.getRuntime().addShutdownHook(
@Override new Thread() {
public void run() { @Override
MGR.shutdownInProgress.set(true); public void run() {
for (Runnable hook: MGR.getShutdownHooksInOrder()) { MGR.shutdownInProgress.set(true);
try { for (Runnable hook: MGR.getShutdownHooksInOrder()) {
hook.run(); try {
} catch (Throwable ex) { hook.run();
LOG.warn("ShutdownHook '" + hook.getClass().getSimpleName() + } catch (Throwable ex) {
"' failed, " + ex.toString(), ex); LOG.warn("ShutdownHook '" + hook.getClass().getSimpleName() +
"' failed, " + ex.toString(), ex);
}
} }
} }
} }
} );
); } catch (IllegalStateException ex) {
// JVM is being shut down. Ignore
LOG.warn("Failed to add the ShutdownHook", ex);
}
} }
/** /**