From 00a0eae4da98b701fa38a6813b1743b754c5c99e Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 7 May 2020 23:29:12 +0300 Subject: [PATCH] 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 --- .../src/org/simantics/diagram/profile/Updater.java | 4 ++-- .../org/simantics/g2d/participant/OrientationRestorer.java | 2 +- .../src/org/simantics/g2d/participant/TimeParticipant.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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() { -- 2.43.2