mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-22 04:26:08 +00:00
perf[executor]: specified map initial size
This commit is contained in:
@@ -48,7 +48,7 @@ public abstract class EventBus {
|
||||
|
||||
private static final ExecutorService[] executors = new ExecutorService[EXECUTORS_SIZE];
|
||||
|
||||
private static final CopyOnWriteHashMapLongObject<ExecutorService> threadMap = new CopyOnWriteHashMapLongObject<>();
|
||||
private static final CopyOnWriteHashMapLongObject<ExecutorService> threadMap = new CopyOnWriteHashMapLongObject<>(EXECUTORS_SIZE);
|
||||
|
||||
private static final Map<Class<? extends IEvent>, List<IEventReceiver>> receiverMap = new HashMap<>();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class TaskBus {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TaskBus.class);
|
||||
|
||||
// 线程池的大小
|
||||
// 线程池的大小,也可以通过provider thread配置指定
|
||||
public static final int EXECUTOR_SIZE;
|
||||
|
||||
private static final ITaskDispatch taskDispatch;
|
||||
@@ -54,8 +54,6 @@ public final class TaskBus {
|
||||
*/
|
||||
private static final ExecutorService[] executors;
|
||||
|
||||
private static final CopyOnWriteHashMapLongObject<ExecutorService> threadMap = new CopyOnWriteHashMapLongObject<>();
|
||||
|
||||
static {
|
||||
var localConfig = NetContext.getConfigManager().getLocalConfig();
|
||||
var providerConfig = localConfig.getProvider();
|
||||
@@ -74,6 +72,8 @@ public final class TaskBus {
|
||||
}
|
||||
}
|
||||
|
||||
private static final CopyOnWriteHashMapLongObject<ExecutorService> threadMap = new CopyOnWriteHashMapLongObject<>(EXECUTOR_SIZE);
|
||||
|
||||
public static class TaskThreadFactory implements ThreadFactory {
|
||||
private final int poolNumber;
|
||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
|
||||
+9
-1
@@ -26,7 +26,15 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
public class CopyOnWriteHashMapLongObject<V> implements Map<Long, V> {
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private volatile LongObjectHashMap<V> map = new LongObjectHashMap<>();
|
||||
private volatile LongObjectHashMap<V> map;
|
||||
|
||||
public CopyOnWriteHashMapLongObject() {
|
||||
map = new LongObjectHashMap<>();
|
||||
}
|
||||
|
||||
public CopyOnWriteHashMapLongObject(int initialCapacity) {
|
||||
map = new LongObjectHashMap<>(initialCapacity);
|
||||
}
|
||||
|
||||
private LongObjectHashMap<V> newCopyMap() {
|
||||
var newMap = new LongObjectHashMap<V>();
|
||||
|
||||
Reference in New Issue
Block a user