mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-18 20:15:06 +00:00
perf[executor]: specified map initial size
This commit is contained in:
1 parent
1c20b6236a
commit
cd55de2b37
3 files changed
+13
-5
No files matched your search
@@ -48,7 +48,7 @@ public abstract class EventBus {
|
|||||||
|
|
||||||
private static final ExecutorService[] executors = new ExecutorService[EXECUTORS_SIZE];
|
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<>();
|
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);
|
private static final Logger logger = LoggerFactory.getLogger(TaskBus.class);
|
||||||
|
|
||||||
// 线程池的大小
|
// 线程池的大小,也可以通过provider thread配置指定
|
||||||
public static final int EXECUTOR_SIZE;
|
public static final int EXECUTOR_SIZE;
|
||||||
|
|
||||||
private static final ITaskDispatch taskDispatch;
|
private static final ITaskDispatch taskDispatch;
|
||||||
@@ -54,8 +54,6 @@ public final class TaskBus {
|
|||||||
*/
|
*/
|
||||||
private static final ExecutorService[] executors;
|
private static final ExecutorService[] executors;
|
||||||
|
|
||||||
private static final CopyOnWriteHashMapLongObject<ExecutorService> threadMap = new CopyOnWriteHashMapLongObject<>();
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
var localConfig = NetContext.getConfigManager().getLocalConfig();
|
var localConfig = NetContext.getConfigManager().getLocalConfig();
|
||||||
var providerConfig = localConfig.getProvider();
|
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 {
|
public static class TaskThreadFactory implements ThreadFactory {
|
||||||
private final int poolNumber;
|
private final int poolNumber;
|
||||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
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> {
|
public class CopyOnWriteHashMapLongObject<V> implements Map<Long, V> {
|
||||||
|
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
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() {
|
private LongObjectHashMap<V> newCopyMap() {
|
||||||
var newMap = new LongObjectHashMap<V>();
|
var newMap = new LongObjectHashMap<V>();
|
||||||
|
|||||||
Reference in new issue
Block a user