Hash wheel Timer It is an algorithm that Netty for the heartbeat timeout check, the performance of the algorithm several co-owned: Ticks per wheel (around tick number), tick Duration (one tick duration) and timeunit (Time unit )。 Left and right tick duration I feel it should be explained for every tick interval.
Hashedwheeltimer the original English gaze expresses such a layer of meaning:
A timer for near real-time I/O network timeout scheduling.
*tick Duration: As described in "near real-time". Hashedwheeltimer will not dispatch on time (very few intervals). Each tick will check to see if TimerTask can be scheduled to run, and you can specify a long or short time tick duration in the constructor to control the accuracy of the dispatch time.
Ticks per Wheel:hashedwheeltimer maintains a data structure called a "time Wheel", where a time-wheel hash table is stored by the hash code of a task's death time.
The default size is 512 hash tables. Assuming you need to schedule a very large number of task timeouts, you can increase this value.
Connection failed reconnection. 500 milliseconds for the first time. Second 1000 milliseconds, ...., n-1 times 5 seconds. Nth Time 5 Seconds
Connection failure time interval maximum 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 (duration of a tick): * As described in "near real-time", Hashedwheeltimer will not be (very few intervals). * Every tick will check to see if TimerTask can be scheduled to run, * You can specify a long or short time tick duration in the constructor to control the accuracy of the dispatch time. * * Can be understood as: every tick interval *---------------------------------------------------------------------------------*ticks per Wheel (tick count): *hashedwheeltimer maintains a data structure called "Time Wheel", and a time-wheel hash table is stored by the hash code of a task's death time.* The default size is 512 hash tables. Assuming you need to schedule a very large number of task timeouts, you can increase this value. * * Can be understood as: agree to the number of timeout, the default is 512. */final Timer timer = new Hashedwheeltimer (timeunit.microseconds); Timer.newtimeout (new TimerTask () {private int t = 0 ;p rivate int count = 1;private int step = 500;public void Run (timeout timeout) throws Exception {System.out.println ("This is a delay "+ t +" run after milliseconds "); if ((Count * Step) <= 5 * +) {t = count * step; System.out.println ("Next run will be delayed" + t + "milliseconds after" + Count + "Times"); count++;} Timeout.gettimer (). Newtimeout (Timeout.gettask (), T, timeunit.milliseconds);}}, and Timeunit.milliseconds);}}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Connection failed connection interval variable