当前位置:网站首页>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
边栏推荐
- Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
- Review the old and know the new: Notes on Data Science
- C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
- C primre plus Chapter 10 question 6 inverted array
- Apache MPM model and ab stress test
- Sdl2 + OpenGL glsl practice (Continued)
- sql语句模糊查询遇到的问题
- Uipath practice (08) - selector
- [BMZCTF-pwn] 18-RCTF-2017-Recho
- 2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
猜你喜欢

JVM原理简介

Source insight garbled code solution

【XSS绕过-防护策略】理解防护策略,更好的绕过

论文阅读_清华ERNIE

2022 P cylinder filling test content and P cylinder filling simulation test questions

I stepped on a foundation pit today

Learn to use the idea breakpoint debugging tool

Basic use of Metasploit penetration testing framework

Network security textual research recommendation

The reason why the entity class in the database is changed into hump naming
随机推荐
2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
Market status and development prospects of the global autonomous marine glider industry in 2022
Summary of training competition (Lao Li's collection of questions)
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
Number of uniform strings of leetcode simple problem
Market status and development prospects of the global IOT active infrared sensor industry in 2022
MediaTek 2023 IC written examination approved in advance (topic)
Sprintf formatter abnormal exit problem
Number of 1 in binary (simple difficulty)
2022 new examination questions for the main principals of hazardous chemical business units and examination skills for the main principals of hazardous chemical business units
Notes | numpy-11 Array operation
The 19th Zhejiang I. barbecue
2022 a special equipment related management (elevator) analysis and a special equipment related management (elevator) simulation test
[SQL injection] joint query (the simplest injection method)
[set theory] binary relationship (definition field | value field | inverse operation | inverse synthesis operation | restriction | image | single root | single value | nature of synthesis operation)
【工具跑SQL盲注】
Retirement plan fails, 64 year old programmer starts work again
Market status and development prospect prediction of global fermentation acid industry in 2022
2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
General undergraduate college life pit avoidance Guide