当前位置:网站首页>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
边栏推荐
- MPM model and ab pressure test
- [BMZCTF-pwn] 18-RCTF-2017-Recho
- Oracle SQL table data loss
- Valentine's day limited withdrawal guide: for one in 200 million of you
- Web security - CSRF (token)
- Market status and development prospects of the global automatic tea picker industry in 2022
- [SQL injection point] location and judgment of the injection point
- UiPath实战(08) - 选取器(Selector)
- JS multidimensional array to one-dimensional array
- Network security textual research recommendation
猜你喜欢

Interface frequency limit access

2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination

Analysis of proxy usage of ES6 new feature

Shuttle + Alluxio 加速内存Shuffle起飞

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

2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank

带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...

Review the old and know the new: Notes on Data Science

《牛客刷verilog》Part II Verilog进阶挑战

Retirement plan fails, 64 year old programmer starts work again
随机推荐
Integration of Android high-frequency interview questions (including reference answers)
document. The problem of missing parameters of referer is solved
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
sql语句模糊查询遇到的问题
Notes | numpy-07 Slice and index
Market status and development prospect prediction of the global autonomous hybrid underwater glider industry in 2022
Concurrent operation memory interaction
Market status and development prospect prediction of the near infrared sensor industry of the global Internet of things in 2022
Sdl2 + OpenGL glsl practice (Continued)
Flutter monitors volume to realize waveform visualization of audio
Market status and development prospect prediction of global SoC Test Platform Industry in 2022
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
Preparation for school and professional cognition
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Wechat applet distance and map
[luatos sensor] 2 air pressure bmp180
【工具跑SQL盲注】
The 19th Zhejiang I. barbecue
雇佣收银员(差分约束)
Market status and development prospect prediction of global fermented plant protein industry in 2022