Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cancelled work from the threadpool queue. #1796

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private static class TimerReference extends SoftReference<TimerListener> {
@Override
public void clear() {
super.clear();
INSTANCE.executor.get().getThreadPool().remove((Runnable) f);
// stop this ScheduledFuture from any further executions
f.cancel(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ public HystrixTimerThreadPoolProperties getTimerThreadPoolProperties() {

}

@Test
public void testCancelledTasksInQueueGetRemoved() {
HystrixTimer timer = HystrixTimer.getInstance();
TestListener l1 = new TestListener(1000, "A");
Reference<TimerListener> l1ref = timer.addTimerListener(l1);

assertTrue(timer.executor.get().getThreadPool().getQueue().size() > 0);

l1ref.clear();

System.out.println("l1 ticks: " + l1.tickCount.get());
assertTrue(l1.tickCount.get() == 0);

assertTrue(timer.executor.get().getThreadPool().getQueue().size() == 0);
}

private static class TestListener implements TimerListener {

private final int interval;
Expand Down