From b726dc97538b7d4ba71fd06c14161017dd67c2b7 Mon Sep 17 00:00:00 2001 From: xubinbin <1323875150@qq.com> Date: 星期三, 10 五月 2023 15:38:22 +0800 Subject: [PATCH] "@schedule"是Spring框架提供的一种定时任务执行机制,默认情况下它是单线程执行,项目中多次使用fixedRate按指定频率执行任务(不管前面任务是否已经完成),在同时执行多个定时任务时可能会出现阻塞和性能问题,为了解决这种单线程瓶颈问题,将定时任务的执行机制改为支持多线程 --- src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java index 1d2b34b..3f24dbe 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java @@ -1,6 +1,7 @@ package com.genersoft.iot.vmp.gb28181.session; import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEventListener; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; @@ -23,14 +24,17 @@ @Autowired private DeferredResultHolder deferredResultHolder; + @Autowired + private RecordEndEventListener recordEndEventListener; - public int put(String deviceId, String sn, int sumNum, List<RecordItem> recordItems) { + public int put(String deviceId,String channelId, String sn, int sumNum, List<RecordItem> recordItems) { String key = deviceId + sn; RecordInfo recordInfo = data.get(key); if (recordInfo == null) { recordInfo = new RecordInfo(); recordInfo.setDeviceId(deviceId); + recordInfo.setChannelId(channelId); recordInfo.setSn(sn.trim()); recordInfo.setSumNum(sumNum); recordInfo.setRecordList(Collections.synchronizedList(new ArrayList<>())); @@ -67,6 +71,7 @@ msg.setKey(msgKey); msg.setData(recordInfo); deferredResultHolder.invokeAllResult(msg); + recordEndEventListener.delEndEventHandler(recordInfo.getDeviceId(),recordInfo.getChannelId()); data.remove(key); } } -- Gitblit v1.8.0