mxsm commented on code in PR #5101:
URL: https://github.com/apache/rocketmq/pull/5101#discussion_r973058728


##########
store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java:
##########
@@ -62,36 +66,37 @@ protected void onWaitEnd() {
     }
 
     public void wakeupAll() {
-        synchronized (this) {
-            boolean needNotify = false;
-
-            for (Boolean value : this.waitingThreadTable.values()) {
-                needNotify = needNotify || !value;
-                value = true;
+        boolean needNotify = false;
+        for (Map.Entry<Long, AtomicBoolean> entry : 
this.waitingThreadTable.entrySet()) {
+            if (entry.getValue().compareAndSet(false, true)) {
+                needNotify = true;
             }
-
-            if (needNotify) {
+        }
+        if (needNotify) {
+            synchronized (this) {
                 this.notifyAll();
             }
         }
     }
 
     public void allWaitForRunning(long interval) {
         long currentThreadId = Thread.currentThread().getId();
+        AtomicBoolean notified = 
this.waitingThreadTable.computeIfAbsent(currentThreadId, k -> new 
AtomicBoolean(false));
+        if (notified.compareAndSet(true, false)) {
+            this.onWaitEnd();
+            return;
+        }

Review Comment:
   how about replace with
   ```java
   AtomicBoolean notified = 
ConcurrentHashMapUtils.computeIfAbsent(this.waitingThreadTable,currentThreadId,k
 -> new AtomicBoolean(false))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to