cigs4/ym-websocket/src/main/java/com/cnbm/websocket/task/SendMessageTask.java
weihongyang f2091d56e2 init
2022-09-13 13:04:55 +08:00

36 lines
1.0 KiB
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<Map.Entry<String, WebSocketServer>> socketIt = WebSocketServer.webSocketMap.entrySet().iterator();
while (socketIt.hasNext()) {
Map.Entry<String, WebSocketServer> socketServerEntry = socketIt.next();
try {
socketServerEntry.getValue().sendMsg("定时发送:"+new Date().toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
log.info("sendMessageTask定时任务正在执行参数为{}", params);
}
}