Hash wheel timer is an algorithm used by netty to perform heartbeat timeout checks. This algorithm has several common attributes: Ticks per Wheel (the number of tick rounds ), tick Duration (the Duration of a tick) and TimeUnit (time unit ). I think the Tick Duration should be interpreted as the interval of each tick.
The original English comment of HashedWheelTimer expresses the following meanings:
One timer schedules near real-time I/O network timeout.
* Tick Duration: As described in "near real-time", HashedWheelTimer does not schedule on time (with few intervals ). Each tick checks whether TimerTask can be scheduled for execution. You can specify a long or short tick duration in the constructor to control the accuracy of the scheduling time.
Ticks per Wheel: HashedWheelTimer maintains a data structure called "time Wheel". The storage of a time Wheel hash table is determined by the hash code of the task's death time. The default size is 512 hash tables. If you need to schedule many tasks to time out, you can increase the value.
The connection fails to be reconnected. The first time is 500 milliseconds, the second time is 1000 milliseconds,..., n-1 seconds, and the nth time is 5 seconds.
Maximum connection failure interval: 5 seconds
Import java. util. concurrent. timeUnit; import org. jboss. netty. util. hashedWheelTimer; import org. jboss. netty. util. timeout; import org. jboss. netty. util. timer; import org. jboss. netty. util. timerTask; public class TimeOutTest {public static void main (String [] argv) {/*-* Tick Duration (the Duration of a tick): * as described in "near real-time, hashedWheelTimer does not schedule tasks on time (with few intervals ). * Each tick checks whether TimerTask can be scheduled for execution. * You can specify a long or short tick duration in the constructor to control the accuracy of the scheduling time. ** It can be understood that each tick interval * seconds * Ticks per Wheel (the number of tick rounds): * HashedWheelTimer maintains a data structure called "time Wheel ", * The storage of a time wheel hash table is determined by the hash code of the task's death time. * The default size is 512 hash tables. If you need to schedule many tasks to time out, you can increase the value. ** It can be understood that the number of allowed timeouts is 512 by default. */Final Timer timer = new HashedWheelTimer (100, TimeUnit. MICROSECONDS); timer. newTimeout (new TimerTask () {private int t = 0; private int count = 1; private int step = 500; public void run (Timeout timeout) throws Exception {System. out. println ("latency" + t + "execution in milliseconds"); if (count * step) <= 5*1000) {t = count * step; System. out. println ("the next execution will be delayed" + t + "milliseconds later" + count + "times"); count ++;} timeout. getTimer (). newTimeout (timeout. getTask (), t, TimeUnit. MILLISECONDS);}, 500, TimeUnit. MILLISECONDS );}}