diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index cc09d09666d..a2fea47dc4b 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -50,6 +50,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -326,6 +327,7 @@ public class ThreadPool extends AbstractComponent implements Closeable { * @return a ScheduledFuture who's get will return when the task is has been added to its target thread pool and throw an exception if * the task is canceled before it was added to its target thread pool. Once the task has been added to its target thread pool * the ScheduledFuture will cannot interact with it. + * @throws java.util.concurrent.RejectedExecutionException {@inheritDoc} */ public ScheduledFuture schedule(TimeValue delay, String executor, Runnable command) { if (!Names.SAME.equals(executor)) { @@ -792,7 +794,11 @@ public class ThreadPool extends AbstractComponent implements Closeable { public void onAfter() { // if this has not been cancelled reschedule it to run again if (run) { - threadPool.schedule(interval, executor, this); + try { + threadPool.schedule(interval, executor, this); + } catch (final RejectedExecutionException e) { + onRejection(e); + } } } } diff --git a/core/src/test/java/org/elasticsearch/threadpool/ScheduleWithFixedDelayTests.java b/core/src/test/java/org/elasticsearch/threadpool/ScheduleWithFixedDelayTests.java index e5be5aa430d..dd1f4991f95 100644 --- a/core/src/test/java/org/elasticsearch/threadpool/ScheduleWithFixedDelayTests.java +++ b/core/src/test/java/org/elasticsearch/threadpool/ScheduleWithFixedDelayTests.java @@ -35,7 +35,6 @@ import org.junit.Before; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference;