perf[map]: get put remove by primitive way

This commit is contained in:
jaysunxiao
2024-09-23 19:50:17 +08:00
parent 082c2fa581
commit 628463dab5
2 changed files with 11 additions and 3 deletions
@@ -70,12 +70,16 @@ public class CopyOnWriteHashMapLongObject<V> implements Map<Long, V> {
return map.get(key);
}
public V getPrimitive(long key) {
public V get(long key) {
return map.get(key);
}
@Override
public V put(Long key, V value) {
return put(key.longValue(), value);
}
public V put(long key, V value) {
lock.lock();
try {
var newMap = newCopyMap();
@@ -89,6 +93,10 @@ public class CopyOnWriteHashMapLongObject<V> implements Map<Long, V> {
@Override
public V remove(Object key) {
return remove(((Long) key).longValue());
}
public V remove(long key) {
lock.lock();
try {
var newMap = newCopyMap();
@@ -117,7 +117,7 @@ public abstract class ThreadUtils {
}
public static Executor executorByThreadId(long threadId) {
var threadExecutor = threadExecutorMap.getPrimitive(threadId);
var threadExecutor = threadExecutorMap.get(threadId);
return threadExecutor == null ? null : threadExecutor.getValue();
}
@@ -125,7 +125,7 @@ public abstract class ThreadUtils {
* search for the corresponding thread by the thread id
*/
public static Thread findThread(long threadId) {
var threadExecutor = threadExecutorMap.getPrimitive(threadId);
var threadExecutor = threadExecutorMap.get(threadId);
if (threadExecutor != null) {
return threadExecutor.getKey();
}