当前位置:网站首页>Handler understands the record
Handler understands the record
2022-07-03 04:52:00 【Baiyun City Lord Haoda】
Catalog
1、 A thread has several handler
2、 A thread has several looper? How to ensure ?
3、handler The cause of the memory leak , Why don't other inner classes have this problem
4、 In the child thread new handler() What preparations should be made before
7、 We use Message How to create
8、Looper.loop() Why doesn't an endless cycle occur anr
handler Mechanism
problem
1、 A thread has several handler
handler adopt new establish handler object , The number of objects depends on new The number of
2、 A thread has several looper? How to ensure ?
A thread has a looper
Whenever executed looper.prepare() Will judge ThreadLocal.get()
Looper Class will define final ThreadLocal attribute ThreadLocal only
ThreadLocal Class maintains an inner ThreadLocalmap class
ThreadLocalmap Of key For threads
value by Created looper
according to ThreadLocalmap Of key You can know that there is only one thread looper
3、handler The cause of the memory leak , Why don't other inner classes have this problem
handler The implementation Anonymous inner classes hold this References to ,handler.enqueueMessage(msg) Time will make msg.target hold handler object .
This problem occurs when the generation period of the inner class is no longer greater than that of the outer class
( Static inner class Weak reference An external class with a dough period )
4、 In the child thread new handler() What preparations should be made before
In the child thread You need to perform looper.prepare() and looper.loop()
In the main thread stay ActivityThread Of main It has already been carried out looper.mainprepare() and looper.loop()
5、 Maintained in a subthread looper, When there is no message in the message queue , What's the usage? ?
call looper.quit()
perform nativewake Wake up the thread
end looper.loop The dead cycle in
6、 Since there can be more than one handler Go to MessageQueue Add data to ( Messages can be sent in different threads ) How does his internal system ensure thread safety
Every looper in Message queue MessageQueue Is the only one.
When executed MessageQueue.enqeueMessage() Will use synchronized Synchronization lock , perform next when Same meeting synchronized, This ensures thread safety
7、 We use Message How to create
1、 Sure new message
2、 Reuse message.obtain()
avoid Memory jitter cause oom
Message in msg.target.dispatchMessage Will perform recycleUnchecked take message Data clearing for
message.next Maintenance queue
8、Looper.loop() Why doesn't an endless cycle occur anr
anr yes Packaged handler news
Itself is a need adopt Looper.loop() To deal with
anr Is with the Looper.loop() Functions unrelated to the loop
边栏推荐
- Number of 1 in binary (simple difficulty)
- Web security - CSRF (token)
- Learn to use the idea breakpoint debugging tool
- Thesis reading_ Chinese medical model_ eHealth
- Hire cashier (differential constraint)
- [set theory] binary relationship (binary relationship notation | binary relationship from a to B | number of binary relationships | example of binary relationship)
- Market status and development prospect prediction of the global fire extinguisher industry in 2022
- Network security textual research recommendation
- Shell script -- condition judgment
- [luatos sensor] 2 air pressure bmp180
猜你喜欢
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
Leetcode simple question: the key with the longest key duration
Thesis reading_ Tsinghua Ernie
Web security - CSRF (token)
Do you know UVs in modeling?
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
论文阅读_中文医疗模型_ eHealth
随机推荐
Market status and development prospect prediction of global fermented plant protein industry in 2022
Truncated sentences of leetcode simple questions
I've seen a piece of code in the past. I don't know what I'm doing. I can review it when I have time
Number of uniform strings of leetcode simple problem
Notes | numpy-07 Slice and index
String matching: find a substring in a string
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
Web security - CSRF (token)
[set theory] binary relation (example of binary relation on a | binary relation on a)
Retirement plan fails, 64 year old programmer starts work again
M1 Pro install redis
Leetcode simple question: check whether two string arrays are equal
Thesis reading_ Chinese medical model_ eHealth
Thesis reading_ Tsinghua Ernie
Hire cashier (differential constraint)
普通本科大学生活避坑指南
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
MySQL winter vacation self-study 2022 12 (3)
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
Current market situation and development prospect forecast of the global fire boots industry in 2022