Stopped executor service will not cause an error in polling strategy.

Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
This commit is contained in:
Tomas Langer
2020-03-10 13:59:21 +01:00
committed by Tomas Langer
parent dfe2fcd29d
commit 425d6ab7cf

View File

@@ -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() {