From f65ca18bda7f7b1818b8ddd87a20d35741eac404 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Wed, 15 Jun 2016 12:03:55 +0200 Subject: [PATCH] Set new policy for central executor pool to avoid loosing data. Signed-off-by: kaizimmerm --- .../scheduling/ExecutorAutoConfiguration.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java index 4f606f1b1..dcda15a36 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java @@ -13,6 +13,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy; import java.util.concurrent.TimeUnit; import org.slf4j.Logger; @@ -63,14 +64,22 @@ public class ExecutorAutoConfiguration { final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(asyncConfigurerProperties.getCorethreads(), asyncConfigurerProperties.getMaxthreads(), asyncConfigurerProperties.getIdletimeout(), TimeUnit.MILLISECONDS, blockingQueue, - new ThreadFactoryBuilder().setNameFormat("central-executor-pool-%d").build()); - threadPoolExecutor.setRejectedExecutionHandler((r, executor) -> LOGGER.warn( - "Reject runnable for centralExecutorService, reached limit of queue size {}", - executor.getQueue().size())); + new ThreadFactoryBuilder().setNameFormat("central-executor-pool-%d").build(), + new PoolSizeExceededPolicy()); return threadPoolExecutor; } + private static class PoolSizeExceededPolicy extends CallerRunsPolicy { + @Override + public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) { + LOGGER.warn( + "Caller has to run on its own instead of centralExecutorService, reached limit of queue size {}", + executor.getQueue().size()); + super.rejectedExecution(r, executor); + } + } + /** * @return the executor for UI background processes. */