-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