From: Tuukka Lehtonen Date: Thu, 7 May 2020 20:29:12 +0000 (+0300) Subject: Replace scheduleAtFixedRate with scheduleWithFixedDelay X-Git-Tag: v1.43.0~29 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F35%2F4235%2F1;p=simantics%2Fplatform.git Replace scheduleAtFixedRate with scheduleWithFixedDelay ScheduledExecutorService.scheduleAtFixedRate tends to run enormous amounts of runnables that would have been scheduled during a machine is in sleep, after the machines wakes up from sleep, retroactively. This is not good and can be avoided by using scheduleWithFixedDelay which is usually good enough regarding the delay between executions. gitlab #531 Change-Id: I4ac3b11f1f9236d411debb352fce610c33410659 (cherry picked from commit 00a0eae4da98b701fa38a6813b1743b754c5c99e) --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Updater.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Updater.java index 44ec7618e..2e79ef216 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Updater.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Updater.java @@ -60,11 +60,11 @@ class Updater implements Runnable { } public void register(INode node) { - // We use ths size of this map to determine whether updates are needed, this is done in AWT thread + // We use the size of this map to determine whether updates are needed, this is done in AWT thread synchronized(requesters) { if(requesters.size() == 0) { if(state.compareAndSet(false, true)) { - ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(this, 0, 500, TimeUnit.MILLISECONDS); + ThreadUtils.getNonBlockingWorkExecutor().scheduleWithFixedDelay(this, 0, 500, TimeUnit.MILLISECONDS); } } ICanvasContext context = DiagramNodeUtil.getPossibleCanvasContext((G2DNode)node); diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/OrientationRestorer.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/OrientationRestorer.java index f2a420b12..aafedcc09 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/OrientationRestorer.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/OrientationRestorer.java @@ -88,7 +88,7 @@ public class OrientationRestorer extends AbstractCanvasParticipant { // long delay = 1000 / 25; this sounds quite frequent long delay = 1000 / 10; lastTrigger = System.currentTimeMillis(); - timer.scheduleAtFixedRate(task, delay, delay, TimeUnit.MILLISECONDS); + timer.scheduleWithFixedDelay(task, delay, delay, TimeUnit.MILLISECONDS); } @HintListener(Class = Hints.class, Field = "KEY_CANVAS_BOUNDS") diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/TimeParticipant.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/TimeParticipant.java index 9103dfd63..7eb4f4c37 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/TimeParticipant.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/TimeParticipant.java @@ -207,7 +207,7 @@ public class TimeParticipant extends AbstractCanvasParticipant { return; long interval = getInterval(); - future = ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(onTimer, DEFAULT_INTERVAL, interval, TimeUnit.MILLISECONDS); + future = ThreadUtils.getNonBlockingWorkExecutor().scheduleWithFixedDelay(onTimer, DEFAULT_INTERVAL, interval, TimeUnit.MILLISECONDS); } private void cancelTimer() {