2323import java .util .HashMap ;
2424import java .util .List ;
2525import java .util .Map ;
26+ import java .util .Set ;
2627import java .util .concurrent .ConcurrentHashMap ;
2728import java .util .concurrent .atomic .AtomicBoolean ;
2829import java .util .concurrent .atomic .AtomicInteger ;
@@ -51,7 +52,7 @@ public class AdaptiveBackOffSpinLockImpl implements AdaptiveBackOffSpinLock {
5152
5253 private final List <AtomicInteger > tpsTable ;
5354
54- private final List <Map <Thread , Byte >> threadTable ;
55+ private final List <Set <Thread >> threadTable ;
5556
5657 private int swapCriticalPoint ;
5758
@@ -65,8 +66,8 @@ public AdaptiveBackOffSpinLockImpl() {
6566 this .locks .put (BACK_OFF_SPIN_LOCK , new BackOffSpinLock ());
6667
6768 this .threadTable = new ArrayList <>(2 );
68- this .threadTable .add (new ConcurrentHashMap <> ());
69- this .threadTable .add (new ConcurrentHashMap <> ());
69+ this .threadTable .add (ConcurrentHashMap . newKeySet ());
70+ this .threadTable .add (ConcurrentHashMap . newKeySet ());
7071
7172 this .tpsTable = new ArrayList <>(2 );
7273 this .tpsTable .add (new AtomicInteger (0 ));
@@ -78,7 +79,7 @@ public AdaptiveBackOffSpinLockImpl() {
7879 @ Override
7980 public void lock () {
8081 int slot = LocalTime .now ().getSecond () % 2 ;
81- this .threadTable .get (slot ).putIfAbsent (Thread .currentThread (), Byte . MAX_VALUE );
82+ this .threadTable .get (slot ).add (Thread .currentThread ());
8283 this .tpsTable .get (slot ).getAndIncrement ();
8384 boolean state ;
8485 do {
0 commit comments