In Android, application responsiveness is monitored by the Activity Manager and Window Manager system services.
and android will display the Application Not Responding (ANR) dialog for a particular application when it detects one of the following conditions:
- No response to an input event (within 5 seconds.
- A BroadcastReceiver hasn't finished executing within 10 seconds.
In case ANR happens, through the method dumpStackTraces() of ActivityManagerService all the information of the thread stack will be saved in /data/anr/ directory.
Then, what we need to find or look at to ?
The following is the testing log snippet...basic investigation steps would be to look for a pattern like "waiting to lock........held by tid=xxx"..
Here Thread ID 12 is hold the task.. so we need to look more closely the problematic method.
"main" prio=5 tid=1 MONITOR
| group="main" sCount=1 dsCount=0 obj=0x410a8c40 self=0xa73c98
| sysTid=704 nice=0 sched=0/0 cgrp=default handle=1075004808
| schedstat=( 0 0 0 ) utm=31475 stm=3384 core=1
at com.test.studio.TestNativeSAP.synchronizedInvoke(TestNativeSAP.java:~246)
- waiting to lock <0x42472270> (a com.test.studio.TestNativeSAP) held by tid=12 (AsyncTask #2)
"AsyncTask #2" prio=5 tid=12 NATIVE
at com.test.studio.TestNativeSAP.startPreview(Native Method)
at com.test.studio.TestNativeSAP.synchronizedInvoke(TestNativeSAP.java:286)
at com.test.studio.TestNativeSAP.invokeStartPreview(TestNativeSAP.java:169)
This is the only example.. trace does not always contain "waiting to lock"
so sometimes it is really hard to find main reason.
Thread States:
- running: executing application code
- sleeping: called Thread.sleep()
- monitor: waiting to acquire a monitor lock
- wait: in Object.wait()
- native: executing native code
- vmwait: waiting on a VM resource
- zombie: thread is in the process of dying
- init: thread is initializing
- starting: thread is about to start
댓글 없음:
댓글 쓰기