如何每5秒netty(服务器)进行一次操作
How to do the operation every 5 seconds netty (Server)
之前在workermanphp做websocket服务器,但是因为经常做java,所以决定研究netty,想知道如何发送hello消息每 5 秒向所有用户发送一次,在 workerman 中,这是通过计时器实现的。
在 Netty 中每 EventLoop extends ScheduledExecutorService 这意味着你可以像这样每 5 秒安排一个任务到 运行:
Channel ch = ...;
ch.eventLoop().scheduleAtFixedRate(() -> {}, 0, 5, TimeUnit.SECONDS);
之前在workermanphp做websocket服务器,但是因为经常做java,所以决定研究netty,想知道如何发送hello消息每 5 秒向所有用户发送一次,在 workerman 中,这是通过计时器实现的。
在 Netty 中每 EventLoop extends ScheduledExecutorService 这意味着你可以像这样每 5 秒安排一个任务到 运行:
Channel ch = ...;
ch.eventLoop().scheduleAtFixedRate(() -> {}, 0, 5, TimeUnit.SECONDS);