diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/PrometheusStats.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/PrometheusStats.java index bdf37f0ffb..c3b42a81a6 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/PrometheusStats.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/stats/PrometheusStats.java @@ -213,7 +213,7 @@ public Map dataErrors() { @Override public void close() { - executor.close(); + executor.shutdown(); push(); } diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/worker/Worker.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/worker/Worker.java index c1d78a0d6e..aec95fe535 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/worker/Worker.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/worker/Worker.java @@ -54,33 +54,33 @@ public Worker(String prefix, Stats stats, int threads, RunnableThatThrows task) public Worker(String prefix, Stats stats, int threads, IntConsumerThatThrows task) { this.prefix = prefix; stats.gauge(prefix + "_threads", threads); - try (var es = Executors.newFixedThreadPool(threads, new NamedThreadFactory(prefix))) { - String parentStage = LogUtil.getStage(); - List> results = new ArrayList<>(); - for (int i = 0; i < threads; i++) { - final int threadId = i; - results.add(CompletableFuture.runAsync(() -> { - LogUtil.setStage(parentStage, prefix); - String id = Thread.currentThread().getName(); - LOGGER.trace("Starting worker"); - try { - long start = System.nanoTime(); - task.accept(threadId); - stats.timers().finishedWorker(prefix, Duration.ofNanos(System.nanoTime() - start)); - } catch (Throwable e) { - System.err.println("Worker " + id + " died"); - // when one worker dies it may close resources causing others to die as well, so only log the first - if (firstWorkerDied.compareAndSet(false, true)) { - e.printStackTrace(); // NOSONAR - } - throwFatalException(e); - } finally { - LOGGER.trace("Finished worker"); + var es = Executors.newFixedThreadPool(threads, new NamedThreadFactory(prefix)); + String parentStage = LogUtil.getStage(); + List> results = new ArrayList<>(); + for (int i = 0; i < threads; i++) { + final int threadId = i; + results.add(CompletableFuture.runAsync(() -> { + LogUtil.setStage(parentStage, prefix); + String id = Thread.currentThread().getName(); + LOGGER.trace("Starting worker"); + try { + long start = System.nanoTime(); + task.accept(threadId); + stats.timers().finishedWorker(prefix, Duration.ofNanos(System.nanoTime() - start)); + } catch (Throwable e) { + System.err.println("Worker " + id + " died"); + // when one worker dies it may close resources causing others to die as well, so only log the first + if (firstWorkerDied.compareAndSet(false, true)) { + e.printStackTrace(); // NOSONAR } - }, es)); - } - done = joinFutures(results); + throwFatalException(e); + } finally { + LOGGER.trace("Finished worker"); + } + }, es)); } + es.shutdown(); + done = joinFutures(results); } /**