From 0526ba9a7daa4cafd39a886976fedf0568bb1464 Mon Sep 17 00:00:00 2001 From: ingvord Date: Fri, 21 May 2021 17:38:49 +0300 Subject: [PATCH] Enforce intial value read --- src/main/java/wpn/hdri/ss/engine2/Engine.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/wpn/hdri/ss/engine2/Engine.java b/src/main/java/wpn/hdri/ss/engine2/Engine.java index 24d4dc7..7cd9751 100644 --- a/src/main/java/wpn/hdri/ss/engine2/Engine.java +++ b/src/main/java/wpn/hdri/ss/engine2/Engine.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -49,9 +50,12 @@ public Engine(ScheduledExecutorService exec, DataStorage storage, private void start(boolean append, long delay){ for(Attribute attr : polledAttributes){ logger.debug("Scheduling polling task for {}", attr.fullName); + PollTask task = new PollTask(attr, storage, append); runningTasks.put(attr.fullName, exec.scheduleWithFixedDelay( - new PollTask(attr, storage, append), 0L, delay == -1 ? attr.delay : delay, TimeUnit.MILLISECONDS)); + task, 0L, delay == -1 ? attr.delay : delay, TimeUnit.MILLISECONDS)); + + CompletableFuture.runAsync(task); } for (Attribute attr : eventDrivenAttributes) { logger.debug("Subscribing to {}", attr.fullName);