]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Reduce the amount of annoying Retry mutex acquire print 39/639/4
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 19 Jun 2017 05:43:05 +0000 (08:43 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 30 Jun 2017 16:32:52 +0000 (19:32 +0300)
refs #7175

Change-Id: If9505ec6b79aeee38971f523bb6f1909493abd81

bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRU.java

index 690ba426f209afd52035ac875530b1f7e2b3d763..48b7d4b10a9b34c80e9a68c7b536ef3840e48867 100644 (file)
@@ -556,18 +556,28 @@ public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
                 boolean gotMutex = impl.tryAcquireMutex();
 
                 boolean done = false;
-                // TODO: fix this properly pleease
                 int count = 0;
+                long startTime = 0;
                 while (!done) {
 
                     if (gotMutex || borrowMutex) {
                         runWithMutex();
                         done = true;
                     } else {
-                        if (count % 100 == 0)
+                        if (count % 10 == 0) {
+                            // Taking too long, sleep for a while.
                             LOGGER.warn("Retry mutex acquire");
+                            try {
+                                Thread.sleep(10);
+                            } catch (InterruptedException e) {
+                            }
+                        }
                         gotMutex = impl.tryAcquireMutex();
-                        count++;
+                        long currentTime = System.currentTimeMillis();
+                        if ((currentTime - startTime) > 10) {
+                            startTime = currentTime;
+                            count++;
+                        }
                     }
 
                 }