|
@@ -2,15 +2,18 @@ package com.persagy.client;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.date.TimeInterval;
|
|
|
+import cn.hutool.core.thread.ExecutorBuilder;
|
|
|
import com.persagy.service.AlarmHandleService;
|
|
|
import com.persagy.utils.GZIPCompressUtil;
|
|
|
import com.persagy.utils.LockUtil;
|
|
|
import com.persagy.utils.StringUtil;
|
|
|
+import io.netty.util.concurrent.RejectedExecutionHandlers;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.java_websocket.WebSocket;
|
|
|
import org.java_websocket.client.WebSocketClient;
|
|
|
import org.java_websocket.handshake.ServerHandshake;
|
|
|
+import org.quartz.SchedulerException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -18,6 +21,10 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
|
+import java.util.concurrent.RejectedExecutionHandler;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
@@ -63,7 +70,12 @@ public class WebSocketClientFactory {
|
|
|
*/
|
|
|
@Value("${project.iotid}")
|
|
|
String iotProjectId;
|
|
|
-
|
|
|
+ ExecutorService executor = ExecutorBuilder.create()
|
|
|
+ .setCorePoolSize(5)
|
|
|
+ .setMaxPoolSize(10)
|
|
|
+ .setWorkQueue(new LinkedBlockingQueue<>(102400))
|
|
|
+ .setHandler(new ThreadPoolExecutor.AbortPolicy())
|
|
|
+ .build();
|
|
|
private WebSocketClient outCallWebSocketClientHolder;
|
|
|
|
|
|
public WebSocketClient getOutCallWebSocketClientHolder() {
|
|
@@ -113,7 +125,7 @@ public class WebSocketClientFactory {
|
|
|
while (!LockUtil.getInstance().isExecute()){
|
|
|
try {
|
|
|
log.warn("等待获取锁....");
|
|
|
- LockUtil.getInstance().lock.lock();
|
|
|
+ LockUtil.getInstance().lock.lockInterruptibly();
|
|
|
log.warn("已经获取锁....");
|
|
|
// try {
|
|
|
// LockUtil.getInstance().condition.await();
|
|
@@ -127,7 +139,15 @@ public class WebSocketClientFactory {
|
|
|
LockUtil.getInstance().lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
- alarmHandleService.handleIOTData(message);
|
|
|
+ log.info("---[{}]",executor.toString());
|
|
|
+ String finalMessage = message;
|
|
|
+ executor.execute(()-> {
|
|
|
+ try {
|
|
|
+ alarmHandleService.handleIOTData(finalMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("数据处理失败", e);
|
|
|
+ }
|
|
|
+ });
|
|
|
} catch (Exception e) {
|
|
|
log.error("数据处理失败", e);
|
|
|
}
|