]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRU.java
Replace System.err and System.out with SLF4J Logging
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / lru / LRU.java
index 80fec7032940ac3e7a6a1abbebb02325880a8bfc..b9ba72121858540c66e7c40d66990f196ecc7cea 100644 (file)
@@ -62,7 +62,7 @@ public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
        public void acquireMutex() throws IllegalAcornStateException {
                try {
                        while(!mutex.tryAcquire(3, TimeUnit.SECONDS)) {
-                               System.err.println("Mutex is taking a long time to acquire - owner is " + mutexOwner);
+                               LOGGER.info("Mutex is taking a long time to acquire - owner is " + mutexOwner);
                        }
                        if(VERIFY)
                                mutexOwner = Thread.currentThread();
@@ -78,7 +78,7 @@ public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
 
        public void shutdown() {
            if (GraphClientImpl2.DEBUG)
-               System.err.println("Shutting down LRU writers " + writers);
+               LOGGER.info("Shutting down LRU writers " + writers);
                writers.shutdown();
                try {
                        writers.awaitTermination(60, TimeUnit.SECONDS);
@@ -97,7 +97,7 @@ public class LRU<MapKey,MapValue extends LRUObject<MapKey, MapValue>> {
                        }
                });
                if (GraphClientImpl2.DEBUG)
-                   System.err.println("Resuming LRU writers " + writers);
+                   LOGGER.info("Resuming LRU writers " + writers);
        }
 
        /*
@@ -556,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 {
-                        LOGGER.warn("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++;
+                        }
                     }
 
                 }