package com.cnbm.websocket.task; import com.cnbm.scheduletask.task.ITask; import com.cnbm.websocket.server.WebSocketServer; import lombok.extern.log4j.Log4j2; import org.springframework.stereotype.Component; import java.io.IOException; import java.util.Date; import java.util.Iterator; import java.util.Map; /** * @Author weihongyang * @Date 2022/6/29 2:01 PM * @Version 1.0 */ @Log4j2 @Component("sendMessageTask") public class SendMessageTask implements ITask { public void run(String params) { Iterator> socketIt = WebSocketServer.webSocketMap.entrySet().iterator(); while (socketIt.hasNext()) { Map.Entry socketServerEntry = socketIt.next(); try { socketServerEntry.getValue().sendMsg("定时发送:"+new Date().toString()); } catch (IOException e) { throw new RuntimeException(e); } } log.info("sendMessageTask定时任务正在执行,参数为:{}", params); } }