Debugging Java InterruptedException i.e. finding the cause
Asked Answered
P

2

6

During debugging of Android app, sometimes InterruptedException occurs and crashes the app. I've been able to set a break-point on default exception handler, but call stack is not informative.

at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1991)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2025)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1048)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:776)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:820)

What is telling is that the interrupted thread is always RxCachedThreadScheduler-4 (or some other number)

What would be a systematic approach towards finding the root cause of the exception?

Protamine answered 19/7, 2018 at 20:35 Comment(4)
The stacktrace should have a location within your code where you use blocking code. Is Retrofit involved?Matins
@Matins there is no mention of my codeProtamine
Set a breakpoint for InterruptedException and step through to see where it is and what it affects. Generally though, there is little chance we could help you without seeing the code.Matins
Do you use any sleep() , join() or wait() method ??? Where ?Indemnity
P
4

Set breakpoint at the method Thread::interrupt and catch the offender. If you think that this interruption should not happen, and you cannot switch off the call which interrupts your thread, then you can override Thread::interrupt in your thread implementation, and force the the thread pool to use your implementation by providing your own ThreadFactory.

Periwig answered 4/8, 2018 at 15:14 Comment(1)
This is an interesting suggestion. I'll try it out.Protamine
G
2

It looks like the crash is happening from a third party code package, you should post your issue with the source project as well for additional help. Please post any code related to how you use this package to help troubleshoot too. Make sure you're using the latest version of this package in case they already fixed this issue. The stack trace isn't very helpful because the other project is launching threads and the crash happens from within one of their threads. Likely, you're not using the package as intended or there is a bug in it that they need to fix.

https://github.com/ReactiveX/RxJava
Gauffer answered 7/8, 2018 at 21:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.