Algorithm implementation of Ring queue efficiently triggering a large number of timeout tasks
The timeout trigger algorithm based on ring queue only needs one timer to trigger batch timeout tasks with low CPU consumption and high efficiency. Introduction to the principle, the following is a simple implementation of this algorithm.
1,TaskHolder.java
Package com.zws.timer;/** @ author wensh.zhu * @ date 2018-04-22 * / public class TaskHolder {/ * * the number of laps the task needs to wait, that is, how many laps the task needs to go * * / private int cycles; private int delays; private Runnable task Public TaskHolder () {} public TaskHolder (int cycles, int delays, Runnable task) {this.cycles = cycles; this.delays = delays; this.task = task;} public boolean isTimeOut () {return cycles