Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

线程池配置以及关闭线程池优化 #88

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Lin728
Copy link

@Lin728 Lin728 commented Jul 4, 2023

线程池配置优化以及优雅关闭线程池

@@ -58,6 +61,7 @@ public ThreadPoolTaskExecutor websocketExecutor() {
executor.setThreadNamePrefix("websocket-executor-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());//满了直接丢弃,默认为不重要消息推送
executor.setThreadFactory(new MyThreadFactory(executor));
executor.setPrestartAllCoreThreads(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处感觉没必要直接启动所有核心线程等待

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下面代码,推动消息给所有在线的人,ONLINE_WS_MAP是所有在线等人数,而且核心线程启动还是需要的
如果初始化时不启动所有核心线程,很短时间内也是会调用所有核心线程的
public void sendToAllOnline(WSBaseResp<?> wsBaseResp, Long skipUid) {
ONLINE_WS_MAP.forEach((channel, ext) -> {
if (ObjectUtil.equal(ext.getUid(), skipUid)) {
return;
}
threadPoolTaskExecutor.execute(() -> sendMsg(channel, wsBaseResp));
});
}

lilin added 4 commits July 6, 2023 15:31
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants