| 123456789101112131415161718192021222324252627282930313233343536373839 |
- package com.tmzn.devicelinkykc.taskQueue;
- import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
- import com.tmzn.devicelinkykc.socket.SocketHandle;
- import com.tmzn.devicelinkykc.taskQueue.queue.MsgTranscationQueue;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.util.Map;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.ScheduledThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
- /**
- * @author xp
- * @date 2024/3/15
- * @explain " "
- */
- @Component
- public class TranscationTask {
- @Autowired
- private MsgTranscationQueue msgTranscationQueue;
- @Autowired
- private SocketHandle socketHandle;
- public void start(){
- ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1);
- Runnable task = new Runnable() {
- @Override
- public void run() {
- Map<String, DeviceConnectionMsg> deviceConnectionMsgMap = socketHandle.getDeviceConnectionMsgMap();
- msgTranscationQueue.add(deviceConnectionMsgMap);
- }
- };
- //每50秒检测要执行的订单
- scheduler.scheduleAtFixedRate(task,10,40*1000, TimeUnit.MILLISECONDS);
- }
- }
|