Replace scheduleAtFixedRate with scheduleWithFixedDelay 19/4219/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 7 May 2020 20:29:12 +0000 (23:29 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 7 May 2020 20:29:12 +0000 (23:29 +0300)
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

bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Updater.java
bundles/org.simantics.g2d/src/org/simantics/g2d/participant/OrientationRestorer.java
bundles/org.simantics.g2d/src/org/simantics/g2d/participant/TimeParticipant.java

index 44ec7618e2fee64577f350633c778316428ae144..2e79ef2160808332339bd79d72d97d4edec14fca 100644 (file)
@@ -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);
index f2a420b1221910c1f54e1dba891ad8417bfcc449..aafedcc09f78b902775a50e8ec76903b486f1b94 100644 (file)
@@ -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")
index 9103dfd638539d6c9e9ad5d93b2e4c1e067614b3..7eb4f4c379a14a2b8ced71fbe5b6841cda93b321 100644 (file)
@@ -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() {