|
@@ -0,0 +1,40 @@
|
|
|
+package com.persagy.client;
|
|
|
+
|
|
|
+import cn.hutool.core.thread.ExecutorBuilder;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 处理webSocket消息的线程池
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2022/1/24 11:24 上午
|
|
|
+ **/
|
|
|
+@Configuration
|
|
|
+public class WebSocketThreadPool {
|
|
|
+ /**
|
|
|
+ * 核心线程数
|
|
|
+ */
|
|
|
+ @Value("${corePoolSize:5}")
|
|
|
+ int corePoolSize;
|
|
|
+ /**
|
|
|
+ * 最大线程数
|
|
|
+ */
|
|
|
+ @Value("${maxPoolSize:10}")
|
|
|
+ int maxPoolSize;
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public ExecutorService executor() {
|
|
|
+ return ExecutorBuilder.create()
|
|
|
+ .setCorePoolSize(corePoolSize)
|
|
|
+ .setMaxPoolSize(maxPoolSize)
|
|
|
+ .setWorkQueue(new LinkedBlockingQueue<>(102400))
|
|
|
+ .setHandler(new ThreadPoolExecutor.AbortPolicy())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+}
|