1

I am investigating a dead lock issue (not ANR) in my Android app. When my app detected a potential dead lock, it prints out stack trace of all live threads using Thread.getAllStackTraces(). But this stack trace info doesn't include waiting and blocked information. I want to programmatically get stack trace with waiting and blocked info like below. Is there a way to do that?

"main" prio=5 tid=1 WAIT
| group="main" sCount=1 dsCount=0 obj=0x418ccea0 self=0x417c7388
| sysTid=13183 nice=-11 sched=0/0 cgrp=apps handle=1074684244
| state=S schedstat=( 0 0 0 ) utm=7 stm=5 core=3
at java.lang.Object.wait(Native Method)
- waiting on <0x42aeb7a8> (a com.myapp.SomeModule)
at java.lang.Object.wait(Object.java:364)
at com.myapp.SomeModule.doSomething(SomeModule.java:45)
Kai
  • 3,775
  • 10
  • 39
  • 54

1 Answers1

0

There is one way to get stack traces when app crashed or thread was terminated, due to unexpected exception.

You can add UncaughtExceptionHandler:

Thread.setDefaultUncaughtExceptionHandler { thread, exception -> 
   // check here for thread info and exception thrown
}

Check for more info on here: https://www.bugsnag.com/blog/error-handling-on-android-part-2

Android documentation about this: https://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler

mmmatey
  • 666
  • 8
  • 15