Jelajahi Sumber

fixed delay for the schedule task

Lukas Cerny 4 tahun lalu
induk
melakukan
5ebce3c5d1

+ 8 - 2
src/main/java/cz/senslog/watchdog/util/schedule/ScheduleTask.java

@@ -8,7 +8,6 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 
 import static cz.senslog.watchdog.util.TimeConverter.secToMillis;
-import static java.time.LocalTime.now;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 public final class ScheduleTask {
@@ -55,7 +54,14 @@ public final class ScheduleTask {
     }
 
     public void schedule(ScheduledExecutorService scheduledService, CountDownLatch latch) {
-        long delay = startAt != null ? now().until(startAt, ChronoUnit.MILLIS) : delayMillis > 0 ? delayMillis : DEFAULT_DELAY_MILLIS;
+
+        long delay = DEFAULT_DELAY_MILLIS;
+        if (startAt != null) {
+            delay = LocalDateTime.now().until(startAt, ChronoUnit.MILLIS);
+        } else if (delayMillis > 0) {
+            delay = delayMillis;
+        }
+        
         ScheduledFuture<?> future = scheduledService.scheduleAtFixedRate(task, delay, periodMillis, MILLISECONDS);
         description = new TaskDescription(description.getName(), Status.RUNNING);
         new Thread(() -> {