superhj1987 / superhj1987.github.io

my homepage and blog
http://www.rowkey.cn
5 stars 4 forks source link

如何实现延时触发/定时器 #9

Open imangry opened 6 years ago

imangry commented 6 years ago

最后这个方案,和Netty里面的HashedWheelTimer是一样的

superhj1987 commented 6 years ago

@imangry 是的,Netty中有这么一个实现,多谢提示。

cocoakekeyu commented 6 years ago

有实践方案吗? python的Celery自己也实现一个定时执行的队列

superhj1987 commented 6 years ago

@cocoakekeyu 方案一可以使用redis的zset按照时间戳为score存入任务,每个一秒使用zrangeByScore获取可触发任务;第二种可以参考ScheduledThreadPoolExecutor.DelayedWorkQueue;时间轮的方案可以参考Netty的HashedWheelTimer。