current position：Home>[Java Interview] After 7 years of work, I went to the byte interview and turned around on this question. Could you please tell me your understanding of the time wheel?
[Java Interview] After 7 years of work, I went to the byte interview and turned around on this question. Could you please tell me your understanding of the time wheel?
2022-08-06 17:39:13【Follow Mic to learn architecture】
Hello everyone, I'm Mic, a Java programmer who has no talent and can only rely on his looks.
A programmer who has been working for 7 years, went to byte interview and was asked the question of the time round.
He came back from the interview and told me that this question was beyond his knowledge. He also found some articles on the Internet to study, but his understanding was not very deep.
Want me to write an interview essay about the time wheel problem.
Who told me to be so kind?Immediately arranged for this fan.
About the question "What is the time wheel, please tell us your understanding of the time wheel",
I put the master's answers into a 10W interview document, you can scan the QR code at the end of the article to get it
Look at the master's answer below
Everyone remember to like, favorite and follow!
Partners who need expert interview documents and interview documents can scan the QR code at the bottom of the articlespan>
The time wheel, simply understood, is a ring-shaped array used to store a series of timed tasks. Its entire working principle is similar to the dial of our clock.
It consists of two parts, one is a ring array and the other is a pointer to traverse the ring array.
First, define a fixed-length ring array, and then each element of the array represents a time scale, assuming it is 1s, then if it is an array of length 8, it represents 8 seconds.
Then, there is a pointer that loops through the array in a clockwise direction, advancing one array index every minimum time unit.
This pointer makes one revolution to represent 8 seconds, and two revolutions to represent 16 seconds. Assuming that it starts from 0:00:00, it will reach 0:00:9 seconds after one revolution.
Each element in the ring array is a container used to store timed tasks. When we add a timed task to the time wheel, we will calculate the array index stored in it according to the execution time of the timed task..
It is possible that there are multiple timed tasks on a certain time scale, which will be stored in a doubly linked list at this time.
When the pointer points to an array, the tasks stored in the array will be taken out, and then the linked list will be traversed to run the tasks in it one by one.
If the execution time of a scheduled task is greater than the length represented by the ring array, a lap number can generally be used to represent the delayed execution time of the task.
That is to say, if it is the task to be executed in the 16th second, it means that this task should be executed at the subscript 0 position of the array in the second circle.
The benefits of using a time wheel to manage multiple scheduled tasks are many, and I think there are two core reasons:
Reduce the time complexity of adding and deleting scheduled tasks and improve performance.
It can guarantee that each execution of the timer task is O(1) complexity. In the case of intensive timer tasks, the performance advantage is very obvious.
Of course, it also has drawbacks, for very time-critical tasks, the time wheel is not very suitable, because the accuracy of the time wheel algorithm depends on the granularity of the smallest time unit.Assuming that 1s is used as a time scale, tasks that are less than 1s cannot be scheduled by time rounding.
The time wheel algorithm is used in many places, such as Dubbo, Netty, Kafka, etc.
The time wheel algorithm is an interesting design.
It is widely used, but in practical applications, most students have very little contact.
I think this design idea or this data structure can also be used for reference in some specific scenarios in our practical application.
Such as timing retry, decay retry, etc.
Also, I made all Java interview series into full interview documents.Its convenience is that you can find the interview questions you want by searching. Currently, 180 issues have been updated, with a total of more than 15W words!
[Partners who want to receive interview documents can click the business card at the bottom of the article to give it to everyone for free!]
Partners who need expert interview documents can scan the QR code below
author[Follow Mic to learn architecture],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Android converts mp3 to AAC and mixes it into video
- Android sketchpad appreciation function code
- 2023 Porsche Macan, the main technology appearance, leads the trend
- The thread to run up, feeling is bind to write wrong, but I don't know what wrong
- Ask for a detailed answer to discarding the highest bit
- About population count in verilog
- Change date format list index out of range
- Kali captures packets, but I haven't seen the device connected to the ap, so I can't capture packets
- ZED2i binocular camera usage tips
- Send data to the front end with nodejs
guess what you like
How to use the BeautifulSoup method to extract the tags in the webpage code, and put the extracted data into the excel file in turn
Nodejs startup error: node:events:505 errno: -32,
The implementation of the dotted line of the HTML+CSS common skills that the front end must know
Front end will be commonly used HTML + CSS skills of mobile terminal 1 px borders
Dedecms dream weaving template front-end list page data duplication solution
C # ListView use skills
DCL singleton mode and how to prevent reflection from destroying singletons
Detailed explanation of SpringBoot tasks
Algorithms - How to Determine Prime Numbers
Basic usage of C++ pair
- Cross compiling under Linux to generate windows program
- JavaSE methods recursive exercises 】 【 create and use of the array
- vue-quill-editor rich text editor will clear spaces for content, filter empty strings, spaces; solution
- Constants and Preprocessors in C
- Use idea to create a multi-module Maven project (inheritance and dependencies between modules)
- Several ways of intercepting List
-  Java operation mode, program structure and notepad++
- Implementation of Permutation and Combination Algorithm in Java
- sql error injection
- Object-Oriented Programming
- 15 tips about SQL optimization
- Spring AOP
- [Short Answer Questions] JavaWeb must ask 10 short answer questions
- How to turn on the wireless screen mirroring function in win7
- Operation and maintenance practice - the latest Nginx binary build and compile lua-nginx-module dynamic link Lua script access Redis database read static resources implicit display
- Win7 wireless network list does not show up Win7 network connection icon disappears what to do
- [Java Interview] This Internet high-frequency interview question stumped 80% of programmers?When does the index expire?
- Win7 and win10 which takes up less resources Win7 and win10 take up resources in detail
- The Voyager Digital: $is expected to start from August 11 to restore rapidly
- windows cannot communicate with the device or resource (primary dns server)
- The get/post request tool (apifox/postman/browser) can request through but the java code can't solve the problem
- "Docker Basics: 2. Docker Installation" includes premise description, basic composition of Docker, Docker platform architecture diagram (architecture version), installation steps, Alibaba Cloud image acceleration, eternal HelloWorld, and underlying princi
- Spring Cloud Gateway integrates Nacos and Swagger to aggregate Api documents
- `Algorithmic Knowledge` Average
- Example of using ElasticsearchRestTemplate in SpringBoot, (add, delete, modify, highlight, id, paginate, time range, and multi-condition queries)
- Ubuntu encountered ERROR: configuration failed for package 'rJava' when installing xlsx package
- Openresty+nginx image server configuration, add http_image_filter_module module
- How to make Zuul support WebSocket
- What does this picture represent?
- "Docker Basics: 3. Docker Common Commands" includes help startup commands, mirroring commands, and mirroring to create containers, which is the fundamental premise (download a CentOS or ubuntu mirror demo), container commands, and a small summary
- Remember to configure the expiration time of @Cacheable (Redis specifies the expiration time of certain Cache Keys)
- [Deployment] Deploy the back-end project to the Pagoda Linux cloud server Java SpringBoot
- `Algorithm knowledge` Prime numbers
- Springcloud gateway gateway+authentication service+token mode, entrance layer authentication unified microservice authentication [design practice]
- (5) Backward compatibility problems in compilation
- Go native development blog project series (the third)
- Blog project (4, initialization)
- See three years of CRUD programmers how to solve the database deadlock
- Kettle Demand Reappears - 100 million details