-1
我知道並使用可用的資源here以編程方式檢測Java中的死鎖。如何在Android中以編程方式檢測死鎖?
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
long ids[] = bean.findMonitorDeadlockedThreads();
if(ids != null)
{
ThreadInfo threadInfo[] = bean.getThreadInfo(ids);
for (ThreadInfo threadInfo1 : threadInfo)
{
System.out.println(threadInfo1.getThreadId()); //Prints the ID of deadlocked thread
System.out.println(threadInfo1.getThreadName()); //Prints the name of deadlocked thread
System.out.println(threadInfo1.getLockName()); //Prints the string representation of an object for which thread has entered into deadlock.
System.out.println(threadInfo1.getLockOwnerId()); //Prints the ID of thread which currently owns the object lock
System.out.println(threadInfo1.getLockOwnerName()); //Prints name of the thread which currently owns the object lock.
}
}
else
{
System.out.println("No Deadlocked Threads");
}
上面的代碼確定並打印死鎖的線程和相關信息。我在Android Studio中嘗試過,發現android不支持這個。有沒有相當於android的?
所以,有沒有簡單的方法!謝啦!我GOOGLE了很多,但找不到任何解決方案,現在我知道爲什麼。 – Feruchemist947