]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRU.java
Reduce the amount of annoying Retry mutex acquire print
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / lru / LRU.java
index 323d66d3df12ea34d2d429293801eeacfc95a23b..48b7d4b10a9b34c80e9a68c7b536ef3840e48867 100644 (file)
@@ -16,16 +16,19 @@ import org.simantics.acorn.ClusterManager;
 import org.simantics.acorn.GraphClientImpl2;
 import org.simantics.acorn.exception.AcornAccessVerificationException;
 import org.simantics.acorn.exception.IllegalAcornStateException;
-import org.simantics.db.common.utils.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /*
  * The order rule of synchronization for LRU and LRUObject is:
- *   § Always lock LRUObject first!
+ *    Always lock LRUObject first!
  * 
  */
 
 public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
-       
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(LRU.class); 
+    
        public static boolean VERIFY = true;
 
        final private long swapTime = 5L*1000000000L;
@@ -148,6 +151,12 @@ public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
                }
        }
 
+       
+       
+       public MapValue purge(MapKey id) {
+               return map.remove(id);
+       }
+
        public MapValue get(MapKey key) throws AcornAccessVerificationException {
                
                if(VERIFY) verifyAccess();
@@ -513,7 +522,7 @@ public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
                            manager.notSafeToMakeSnapshot(new IllegalAcornStateException(t));
                        }
                        t.printStackTrace();
-                       Logger.defaultLogError(t);
+                       LOGGER.error("Exception happened in WriteRunnable.run", t);
                    }
                }
 
@@ -547,14 +556,28 @@ public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
                 boolean gotMutex = impl.tryAcquireMutex();
 
                 boolean done = false;
+                int count = 0;
+                long startTime = 0;
                 while (!done) {
 
                     if (gotMutex || borrowMutex) {
                         runWithMutex();
                         done = true;
                     } else {
-                        System.err.println("Retry mutex acquire");
+                        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();
+                        long currentTime = System.currentTimeMillis();
+                        if ((currentTime - startTime) > 10) {
+                            startTime = currentTime;
+                            count++;
+                        }
                     }
 
                 }