I want to use Redis to design a timeout center,tasks with execution time will be saved to ZSet.At this point, start a thread and continuously perform two operations on ZSet:

1.Check if the minimum score in ZSET is less than the current time

2.If the check is successful,pop the minimum item in ZSET

But when ZSET has no data for a long time, it will waste CPU resources.

At this point, I should sleep() for a period of time when there is no data in ZSET, or use the wait-notify method (let the thread wait to obtain the difference between the execution time of the first pending task from ZSET and the current time, but notify() when a new task is inserted into ZSET,because the newly inserted task may execute earlier than the first task)

New contributor

Odnj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.