From 457c1f4d850eb6b85926dc1e1f90fc0abce58f18 Mon Sep 17 00:00:00 2001 From: JFronny Date: Thu, 23 Feb 2023 17:39:15 +0100 Subject: [PATCH] [config-core] sleep 1s between iterations in watch service loop to free up CPU (wasn't needed that often anyway) --- .../io/gitlab/jfronny/libjf/coprocess/ThreadCoProcess.java | 2 +- .../jfronny/libjf/config/impl/JfConfigWatchService.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libjf-base/src/main/java/io/gitlab/jfronny/libjf/coprocess/ThreadCoProcess.java b/libjf-base/src/main/java/io/gitlab/jfronny/libjf/coprocess/ThreadCoProcess.java index 79801a4..6f8ad40 100644 --- a/libjf-base/src/main/java/io/gitlab/jfronny/libjf/coprocess/ThreadCoProcess.java +++ b/libjf-base/src/main/java/io/gitlab/jfronny/libjf/coprocess/ThreadCoProcess.java @@ -7,7 +7,7 @@ public abstract class ThreadCoProcess implements CoProcess, Runnable { public void start() { if (th != null) stop(); closed = false; - th = new Thread(this); + th = new Thread(this, getClass().getSimpleName()); th.start(); } diff --git a/libjf-config-core-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/JfConfigWatchService.java b/libjf-config-core-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/JfConfigWatchService.java index ba9e239..44127aa 100644 --- a/libjf-config-core-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/JfConfigWatchService.java +++ b/libjf-config-core-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/JfConfigWatchService.java @@ -49,6 +49,11 @@ public class JfConfigWatchService extends ThreadCoProcess implements Closeable { @Override public void executeIteration() { + try { + Thread.sleep(1000); + } catch (InterruptedException ignored) { + return; + } synchronized (CONFIG_DIR) { WatchKey key = service.poll(); if (key != null) {