This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit 0bed921705f0cea05db7df03c765088f4b1ed27c Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Mar 16 14:31:04 2020 +0100 CAMEL-14642: camel-spring-boot - Using max duration and shutdown before should terminate scheduled thread quicker --- .../org/apache/camel/spring/boot/CamelMainRunController.java | 4 ++++ .../spring/boot/CamelSpringBootApplicationController.java | 4 ++++ .../camel/spring/boot/CamelSpringBootApplicationListener.java | 10 +++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelMainRunController.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelMainRunController.java index 6a9771f..1eaeba6 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelMainRunController.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelMainRunController.java @@ -43,6 +43,10 @@ public class CamelMainRunController { return controller.getLatch(); } + public Runnable getMainCompleteTask() { + return controller.getMainCompletedTask(); + } + public AtomicBoolean getCompleted() { return controller.getCompleted(); } diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java index eacf037..38a208a 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java @@ -77,6 +77,10 @@ public class CamelSpringBootApplicationController { return this.latch; } + public Runnable getMainCompletedTask() { + return main.getCompleteTask(); + } + public AtomicBoolean getCompleted() { return completed; } diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java index 325731f..dd79b26 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java @@ -120,7 +120,7 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C if (configurationProperties.getDurationMaxSeconds() > 0) { LOG.info("CamelSpringBoot will terminate after {} seconds", configurationProperties.getDurationMaxSeconds()); terminateMainControllerAfter(camelContext, configurationProperties.getDurationMaxSeconds(), - controller.getCompleted(), controller.getLatch()); + controller.getCompleted(), controller.getLatch(), controller.getMainCompleteTask()); } camelContext.addStartupListener(new StartupListener() { @@ -218,7 +218,8 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C // Helpers - private void terminateMainControllerAfter(final CamelContext camelContext, int seconds, final AtomicBoolean completed, final CountDownLatch latch) { + private void terminateMainControllerAfter(final CamelContext camelContext, int seconds, final AtomicBoolean completed, + final CountDownLatch latch, final Runnable mainCompletedTask) { ScheduledExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelSpringBootTerminateTask"); final AtomicBoolean running = new AtomicBoolean(); @@ -234,6 +235,7 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C } finally { completed.set(true); latch.countDown(); + mainCompletedTask.run(); } running.set(false); }; @@ -249,6 +251,7 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C future.cancel(true); // trigger shutdown latch.countDown(); + mainCompletedTask.run(); } } }); @@ -282,7 +285,8 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C }); } - private void terminateApplicationContext(final ConfigurableApplicationContext applicationContext, final CamelContext camelContext, final CountDownLatch latch) { + private void terminateApplicationContext(final ConfigurableApplicationContext applicationContext, final CamelContext camelContext, + final CountDownLatch latch) { ExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadExecutor(this, "CamelSpringBootTerminateTask"); final AtomicBoolean running = new AtomicBoolean();