You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kylin.apache.org by GitBox <gi...@apache.org> on 2018/09/26 06:26:36 UTC

[GitHub] hit-lacus closed pull request #253: KYLIN-3578 Condition replaces the use of the Object monitor methods

hit-lacus closed pull request #253: KYLIN-3578 Condition replaces the use of the Object monitor methods
URL: https://github.com/apache/kylin/pull/253
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-common/src/main/java/org/apache/kylin/common/util/MemoryBudgetController.java b/core-common/src/main/java/org/apache/kylin/common/util/MemoryBudgetController.java
index c19c07e61b..70dc35715f 100644
--- a/core-common/src/main/java/org/apache/kylin/common/util/MemoryBudgetController.java
+++ b/core-common/src/main/java/org/apache/kylin/common/util/MemoryBudgetController.java
@@ -20,6 +20,7 @@
 
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.slf4j.Logger;
@@ -68,6 +69,7 @@ public NotEnoughBudgetException(Throwable cause) {
     private final ConcurrentMap<MemoryConsumer, ConsumerEntry> booking = new ConcurrentHashMap<MemoryConsumer, ConsumerEntry>();
     private int totalReservedMB;
     private final ReentrantLock lock = new ReentrantLock();
+    private Condition memoryCondition = lock.newCondition();
 
     public MemoryBudgetController(int totalBudgetMB) {
         Preconditions.checkArgument(totalBudgetMB >= 0);
@@ -116,13 +118,14 @@ public void reserveInsist(MemoryConsumer consumer, int requestMB) {
             if (waitStart == 0)
                 waitStart = System.currentTimeMillis();
 
-            synchronized (lock) {
-                try {
-                    lock.wait();
-                } catch (InterruptedException e) {
-                    Thread.currentThread().interrupt();
-                    throw new NotEnoughBudgetException(e);
-                }
+            try {
+                lock.lock();
+                memoryCondition.await();
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                throw new NotEnoughBudgetException(e);
+            }finally {
+                lock.unlock();
             }
         }
     }
@@ -231,9 +234,7 @@ private boolean updateBookingWithDelta(MemoryConsumer consumer, int delta) {
         }
 
         if (delta < 0) {
-            synchronized (lock) {
-                lock.notifyAll();
-            }
+            memoryCondition.signalAll();
         }
 
         return true;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services