// same thread otherwise use one additional thread to invoke them.
final Map<ShutdownContext,GracefulShutdownListener> contexts =
new HashMap<ShutdownContext,GracefulShutdownListener>(listenerCount);
if (gracePeriod <= 0) {
for (final GracefulShutdownListener l : shutdownListeners) {
final ShutdownContext ctx = createContext(contexts, l, shutdownLatch);
l.shutdownRequested(ctx);
}
} else {
shutdownService.execute(new Runnable() {
@Override
public void run() {
for (final GracefulShutdownListener l : shutdownListeners) {
final ShutdownContext ctx = createContext(contexts, l, shutdownLatch);
l.shutdownRequested(ctx);
}
}
});
}