Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ public boolean removeShutdownHook(Runnable shutdownHook) {
throw new IllegalStateException("Shutdown in progress, cannot remove a " +
"shutdownHook");
}
return hooks.remove(new HookEntry(shutdownHook, 0));
// hooks are only == by runnable
return hooks.remove(new HookEntry(shutdownHook, 0, TIMEOUT_MINIMUM,
TIME_UNIT_DEFAULT));
}

/**
Expand All @@ -354,7 +356,9 @@ public boolean removeShutdownHook(Runnable shutdownHook) {
@InterfaceAudience.Public
@InterfaceStability.Stable
public boolean hasShutdownHook(Runnable shutdownHook) {
return hooks.contains(new HookEntry(shutdownHook, 0));
// hooks are only == by runnable
return hooks.remove(new HookEntry(shutdownHook, 0, TIMEOUT_MINIMUM,
TIME_UNIT_DEFAULT));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ public void shutdownHookManager() {
mgr.getShutdownHooksInOrder().size());
}

@Test
public void testShutdownRemove() throws Throwable {
ShutdownHookManager mgr = ShutdownHookManager.get();
assertNotNull("No ShutdownHookManager", mgr);
assertEquals(0, mgr.getShutdownHooksInOrder().size());
Hook hook1 = new Hook("hook1", 0, false);
Hook hook2 = new Hook("hook2", 0, false);
mgr.addShutdownHook(hook1, 9); // create Hook1 with priority 9
assertTrue(mgr.hasShutdownHook(hook1)); // hook1 lookup works
assertEquals(1, mgr.getShutdownHooksInOrder().size()); // 1 hook
assertFalse(mgr.removeShutdownHook(hook2)); // can't delete hook2
assertTrue(mgr.removeShutdownHook(hook1)); // can delete hook1
assertEquals(0, mgr.getShutdownHooksInOrder().size()); // no more hooks
}

@Test
public void testShutdownTimeoutConfiguration() throws Throwable {
// set the shutdown timeout and verify it can be read back.
Expand Down