Browse Source

处理iot消息的executor参数可配置

zhangqiankun 2 years ago
parent
commit
c36448e7cc
1 changed files with 16 additions and 5 deletions
  1. 16 5
      src/main/java/com/persagy/client/WebSocketClientFactory.java

+ 16 - 5
src/main/java/com/persagy/client/WebSocketClientFactory.java

@@ -12,6 +12,7 @@ import org.java_websocket.WebSocket;
 import org.java_websocket.client.WebSocketClient;
 import org.java_websocket.handshake.ServerHandshake;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -40,13 +41,23 @@ import lombok.extern.slf4j.Slf4j;
  * // 项目启动的时候打开websocket连接
  * webSocketClientFactory.retryOutCallWebSocketClient();
  **/
-@Component
 @Slf4j
+@Component
 public class WebSocketClientFactory {
-    ExecutorService executor = ExecutorBuilder.create()
-            .setCorePoolSize(5)
-            .setMaxPoolSize(10)
-            .setWorkQueue(new LinkedBlockingQueue<>(102400))
+	
+	@Value("${config.executor.core-pool-size:10}")
+	private int iotCorePoolSize = 10;
+	
+	@Value("${config.executor.max-pool-size:20}")
+	private int iotMaxPoolSize = 20;
+	
+	@Value("${config.executor.work-queue-size:204800}")
+	private int iotWorkQueueSize = 204800;
+	
+	private ExecutorService executor = ExecutorBuilder.create()
+            .setCorePoolSize(iotCorePoolSize)
+            .setMaxPoolSize(iotMaxPoolSize)
+            .setWorkQueue(new LinkedBlockingQueue<>(iotWorkQueueSize))
             .setHandler(new ThreadPoolExecutor.AbortPolicy())
             .build();