The reconnection interval of connection failure is variable.

Source: Internet
Author: User
Tags rounds jboss

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 );}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.