summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2020-12-09 21:12:44 +0100
committerJon Marius Venstad <venstad@gmail.com>2020-12-09 21:12:44 +0100
commitc8f8e85351b70a02b9915b6978dd05e1c2cc55c7 (patch)
treeccd03852e91dfd64838ac3d46e3ed00084f34188 /vespajlib
parent0107067c0a9c29dd4e60231ad79e35786c390626 (diff)
Split (async) shutdown and (sync) wait for it, and use lists in all maintainer owners
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java
index 2c123779a1e..2bf91775ecc 100644
--- a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java
+++ b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java
@@ -11,6 +11,7 @@ import java.util.Objects;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -21,7 +22,7 @@ import java.util.logging.Logger;
* @author mpolden
* @author jonmv
*/
-public abstract class Maintainer implements Runnable, AutoCloseable {
+public abstract class Maintainer implements Runnable {
protected final Logger log = Logger.getLogger(this.getClass().getName());
@@ -30,6 +31,7 @@ public abstract class Maintainer implements Runnable, AutoCloseable {
private final JobMetrics jobMetrics;
private final Duration interval;
private final ScheduledExecutorService service;
+ private AtomicBoolean shutDown = new AtomicBoolean();
public Maintainer(String name, Duration interval, Instant startedAt, JobControl jobControl, JobMetrics jobMetrics, List<String> clusterHostnames) {
this(name, interval, staggeredDelay(interval, startedAt, HostName.getLocalhost(), clusterHostnames), jobControl, jobMetrics);
@@ -60,10 +62,16 @@ public abstract class Maintainer implements Runnable, AutoCloseable {
log.log(Level.FINE, () -> "Finished " + this.getClass().getSimpleName());
}
- @Override
+ /** Starts shutdown of this, typically by shutting down executors. {@link #close()} waits for shutdown to complete. */
+ public void shutdown() {
+ if ( ! shutDown.getAndSet(true))
+ service.shutdown();
+ }
+
+ /** Waits for shutdown to complete, calling {@link #shutdown} if this hasn't been done already. */
public void close() {
+ shutdown();
var timeout = Duration.ofSeconds(30);
- service.shutdown();
try {
if (!service.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
log.log(Level.WARNING, "Maintainer " + name() + " failed to shutdown " +