From 1b81080f6f7da35d2af7d194a5aa7be720d1eaa4 Mon Sep 17 00:00:00 2001 From: yangjunyi Date: Tue, 29 Aug 2023 14:23:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=9A=E9=81=93=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E5=90=8C=E6=AD=A5=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/cmd/CatalogResponseMessageHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java index 8648dc45..5c977a50 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicBoolean; /** * 目录查询的回复 @@ -60,6 +61,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp @Autowired private SipConfig sipConfig; + private AtomicBoolean processing = new AtomicBoolean(false); @Override public void afterPropertiesSet() throws Exception { @@ -68,7 +70,6 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp @Override public void handForDevice(RequestEvent evt, Device device, Element element) { - boolean isEmpty = taskQueue.isEmpty(); taskQueue.offer(new HandlerCatchData(evt, device, element)); // 回复200 OK try { @@ -76,8 +77,8 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp } catch (SipException | InvalidArgumentException | ParseException e) { logger.error("[命令发送失败] 目录查询回复: {}", e.getMessage()); } - // 如果不为空则说明已经开启消息处理 - if (isEmpty) { + // 已经开启消息处理则跳过 + if (processing.compareAndSet(false, true)) { taskExecutor.execute(() -> { while (!taskQueue.isEmpty()) { // 全局异常捕获,保证下一条可以得到处理 @@ -146,11 +147,12 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp } } - }catch (Exception e) { + } catch (Exception e) { logger.warn("[收到通道] 发现未处理的异常, \r\n{}", evt.getRequest()); logger.error("[收到通道] 异常内容: ", e); } } + processing.set(false); }); }