TranscationTask.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.tmzn.devicelinkykc.taskQueue;
  2. import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
  3. import com.tmzn.devicelinkykc.socket.SocketHandle;
  4. import com.tmzn.devicelinkykc.taskQueue.queue.MsgTranscationQueue;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Component;
  7. import java.util.Map;
  8. import java.util.concurrent.ScheduledExecutorService;
  9. import java.util.concurrent.ScheduledThreadPoolExecutor;
  10. import java.util.concurrent.TimeUnit;
  11. /**
  12. * @author xp
  13. * @date 2024/3/15
  14. * @explain " "
  15. */
  16. @Component
  17. public class TranscationTask {
  18. @Autowired
  19. private MsgTranscationQueue msgTranscationQueue;
  20. @Autowired
  21. private SocketHandle socketHandle;
  22. public void start(){
  23. ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1);
  24. Runnable task = new Runnable() {
  25. @Override
  26. public void run() {
  27. Map<String, DeviceConnectionMsg> deviceConnectionMsgMap = socketHandle.getDeviceConnectionMsgMap();
  28. msgTranscationQueue.add(deviceConnectionMsgMap);
  29. }
  30. };
  31. //每50秒检测要执行的订单
  32. scheduler.scheduleAtFixedRate(task,10,40*1000, TimeUnit.MILLISECONDS);
  33. }
  34. }