Android跨进程调用,Binder线程池溢出导致ANR
如果发生ANR,找到trace.txt 、/data/anr目录下,
json
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x72c33e38 self=0x78a64c2a00
| sysTid=1863 nice=0 cgrp=default sched=0/0 handle=0x792b5f49a8
| state=S schedstat=( 2587940558080 1667956760666 8922333 ) utm=201251 stm=57543 core=7 HZ=100
| stack=0x7fd02c9000-0x7fd02cb000 stackSize=8MB
| held mutexes=
kernel: (couldn't read /proc/self/task/1863/stack)
native: #00 pc 000000000007a2c4 /system/lib64/libc.so (__ioctl+4)
native: #01 pc 0000000000027a34 /system/lib64/libc.so (ioctl+132)
native: #02 pc 0000000000058458 /system/lib64/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+252)
native: #03 pc 000000000005912c /system/lib64/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+60)
native: #04 pc 0000000000058f68 /system/lib64/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+216)
native: #05 pc 000000000004f3ec /system/lib64/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+72)
native: #06 pc 0000000000127890 /system/lib64/libandroid_runtime.so (???)
native: #07 pc 000000000093b1e4 /system/framework/arm64/boot-framework.oat (Java_android_os_BinderProxy_transactNative__ILandroid_os_Parcel_2Landroid_os_Parcel_2I+196)
at android.os.BinderProxy.transactNative(Native method)
at android.os.BinderProxy.transact(Binder.java:769)
at android.app.IActivityManager$Stub$Proxy.getCurrentUser(IActivityManager.java:7528)
at android.app.ActivityManager.getCurrentUser(ActivityManager.java:4081)
sysTid=1863是进程号,ANR发生在at android.os.BinderProxy.transactNative(Native method),在transcatNative函数中,transcatNative 函数式客户端发起端的函数,猜测这是Binder卡住,客户端等待响应中,
我们可以去查看针对性的binder运行日志
cat transactions这个文件来查看运行状况的,
这个地方连续出现thread很多次,猜测是binder线程池耗尽了
这种问题基本上就是我们在跨进程通信调用服务端的时候太频繁了,大部分原因是由于业务逻辑,才会写这种代码,解决办法就是降低调用的频率,或者延迟调用,设置一些时间间隔,app端不要频繁调用服务端。