In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what the Handler Principle is. It is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something from the detailed introduction of this article.
What is the principle of Handler:
Handler encapsulates the message sending (mainly including who the message is sent to sendToTarget, sent to yourself by default)
Looper
It contains a message queue inside, that is, MessageQueue, and all messages sent by Handler go to this message queue.
Looper.Looper method, is an endless loop, constantly get messages from MessageQueue, if there is a message to process the message, no message to block
MessageQueue: A message queue where messages can be added and processed.
Handler is also very simple, the internal will be associated with the Looper, that is to say, in the Handler can find the Looper, find the Looper will find the MessageQueen, send messages in the Handler, in fact, send messages to the MessageQueen queue
Summary: handler copies and sends messages, Looper is responsible for receiving messages sent by Handler and directly transmitting messages to handler itself, MessageQueue is a container for storing messages
Threadlocal is used to store some variable information in the thread, such as set(store variables in Threadlocal), get(get variables from Threadlocal)
As you can see from the Handler source code, creating a Handler automatically creates a Looper object.
From the Looper source code, you can see that Looper contains messageQueen member variables. In fact, the purpose of creating Looper is to obtain MessageQueen.
As you can see from the follow-up source code of sendEmptyMessage of Handler, the mechanism of handler sending messages is implemented through messagequeue.
messageQueue is implemented by sending messageQueue to Handler via an endless loop in Looper.loop(); method
The above picture is a screenshot from Mu class network to understand the principle of Handler through illustration.
What is the Handler Principle? Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.