This is an automated email from the ASF dual-hosted git repository.

tianliuliu pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 1a747d1472 opti: opti thread count in adaptiveBackOffSpinLock (#9530)
1a747d1472 is described below

commit 1a747d147267e28350f9e2cd338635ea74d0073d
Author: hqbfz <[email protected]>
AuthorDate: Thu Jul 10 10:19:10 2025 +0800

    opti: opti thread count in adaptiveBackOffSpinLock (#9530)
    
    Co-authored-by: hqbfzwang <[email protected]>
---
 .../apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java  | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java
 
b/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java
index b4abb08271..1dfbd4718b 100644
--- 
a/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java
+++ 
b/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -51,7 +52,7 @@ public class AdaptiveBackOffSpinLockImpl implements 
AdaptiveBackOffSpinLock {
 
     private final List<AtomicInteger> tpsTable;
 
-    private final List<Map<Thread, Byte>> threadTable;
+    private final List<Set<Thread>> threadTable;
 
     private int swapCriticalPoint;
 
@@ -65,8 +66,8 @@ public class AdaptiveBackOffSpinLockImpl implements 
AdaptiveBackOffSpinLock {
         this.locks.put(BACK_OFF_SPIN_LOCK, new BackOffSpinLock());
 
         this.threadTable = new ArrayList<>(2);
-        this.threadTable.add(new ConcurrentHashMap<>());
-        this.threadTable.add(new ConcurrentHashMap<>());
+        this.threadTable.add(ConcurrentHashMap.newKeySet());
+        this.threadTable.add(ConcurrentHashMap.newKeySet());
 
         this.tpsTable = new ArrayList<>(2);
         this.tpsTable.add(new AtomicInteger(0));
@@ -78,7 +79,7 @@ public class AdaptiveBackOffSpinLockImpl implements 
AdaptiveBackOffSpinLock {
     @Override
     public void lock() {
         int slot = LocalTime.now().getSecond() % 2;
-        this.threadTable.get(slot).putIfAbsent(Thread.currentThread(), 
Byte.MAX_VALUE);
+        this.threadTable.get(slot).add(Thread.currentThread());
         this.tpsTable.get(slot).getAndIncrement();
         boolean state;
         do {

Reply via email to