diff --git a/config/config/src/main/java/io/helidon/config/ScheduledPollingStrategy.java b/config/config/src/main/java/io/helidon/config/ScheduledPollingStrategy.java index 1ab47920a..0bd20b6f6 100644 --- a/config/config/src/main/java/io/helidon/config/ScheduledPollingStrategy.java +++ b/config/config/src/main/java/io/helidon/config/ScheduledPollingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,14 @@ package io.helidon.config; import java.time.Duration; import java.time.Instant; import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; +import java.util.logging.Level; +import java.util.logging.Logger; import io.helidon.config.spi.ChangeEventType; import io.helidon.config.spi.PollingStrategy; @@ -32,6 +35,8 @@ import io.helidon.config.spi.PollingStrategy; * A strategy which allows the user to schedule periodically fired polling event. */ public final class ScheduledPollingStrategy implements PollingStrategy { + private static final Logger LOGGER = Logger.getLogger(ScheduledPollingStrategy.class.getName()); + /* * This class will trigger checks in a periodic manner. * The actual check if the source has changed is done elsewhere, this is just responsible for telling us @@ -108,9 +113,19 @@ public final class ScheduledPollingStrategy implements PollingStrategy { } private void scheduleNext() { - scheduledFuture = executor.schedule(this::fireEvent, - recurringPolicy.interval().toMillis(), - TimeUnit.MILLISECONDS); + try { + scheduledFuture = executor.schedule(this::fireEvent, + recurringPolicy.interval().toMillis(), + TimeUnit.MILLISECONDS); + } catch (RejectedExecutionException e) { + if (executor.isShutdown()) { + // intentional shutdown of an executor service + LOGGER.log(Level.FINEST, "Executor service is shut down, polling is terminated for " + this, e); + } else { + // exceptional condition + LOGGER.log(Level.SEVERE, "Failed to schedule next polling for " + this + ", polling will stop", e); + } + } } private synchronized void fireEvent() {