mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-28 20:09:14 +08:00
opti: opti thread count in adaptiveBackOffSpinLock (#9530)
Co-authored-by: hqbfzwang <hqbfzwang@tencent.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user