From c480c88ba920f20f974628cf5ef18667ab3b0ef5 Mon Sep 17 00:00:00 2001 From: ymlam Date: Sat, 9 Mar 2024 10:30:27 -0500 Subject: [PATCH] Close window of missing clock action on a heavily loaded system. The clock thread may not wake up during the daily pause and daily resume minute, and when it does not, the corresponding wall clock action will be missed. The fix is in checkout the time of operations every time the clock thread wakes up. There is no longer need for the clock to wake up in the middle of a wall clock minute. So we improved the user experience by waking up this thread at the beginning of every minute. --- src/main/java/altk/comm/engine/Broadcast.java | 3 +++ src/main/java/altk/comm/engine/CommEngine.java | 18 ++++-------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/altk/comm/engine/Broadcast.java b/src/main/java/altk/comm/engine/Broadcast.java index 1aa41b9..dcc9220 100644 --- a/src/main/java/altk/comm/engine/Broadcast.java +++ b/src/main/java/altk/comm/engine/Broadcast.java @@ -1021,6 +1021,7 @@ public abstract class Broadcast protected String resume(String reason) { if (reason == ACTION_BY_CLOCK) { boolean inAcceptqble = false; + if (this.reason == null) return null; for (String acceptable : getPauseModesResumableByClock()) { if (this.reason.equalsIgnoreCase(acceptable)) inAcceptqble = true; } @@ -1437,6 +1438,8 @@ public abstract class Broadcast if (state == BroadcastState.ABORTED) return; if (!withinOperatingHours()) { pause(ACTION_BY_CLOCK, null); + } else { + resume(ACTION_BY_CLOCK, null); } } diff --git a/src/main/java/altk/comm/engine/CommEngine.java b/src/main/java/altk/comm/engine/CommEngine.java index f8e4d02..c53770d 100644 --- a/src/main/java/altk/comm/engine/CommEngine.java +++ b/src/main/java/altk/comm/engine/CommEngine.java @@ -95,25 +95,15 @@ public abstract class CommEngine extends HttpServlet { while (!threadShouldStop) { - String timeOfDay = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm")); // Check for pause for (Broadcast broadcast : broadcasts.values()) - {; - // Check for pause - if (broadcast.daily_stop.length() > 0) - { - if (timeOfDay.equals(broadcast.daily_stop)) broadcast.pause("clock", null); - } - - // Check for resume - if (broadcast.daily_start.length() > 0) - { - if (timeOfDay.equals(broadcast.daily_start)) broadcast.resume(Broadcast.ACTION_BY_CLOCK); - } + { + broadcast.enforceOperationHours(); } + // sleep till next wall clock minute long currentTime = System.currentTimeMillis(); - long sleepTime = 60000 + 30000 - currentTime % 60000; + long sleepTime = 60000 - currentTime % 60000; if (sleepTime > 0) { try