gpt4 book ai didi

java - 如何在 Android 中以编程方式检测死锁?

转载 作者:行者123 更新时间:2023-12-01 17:59:22 29 4
gpt4 key购买 nike

我知道并使用了可用资源 here在 Java 中以编程方式检测死锁。

  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 中有类似的吗?

最佳答案

ThreadMXBean 不是 Android 框架的一部分。这个问题已经在这里出现Android finding a deadlock

关于java - 如何在 Android 中以编程方式检测死锁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42246427/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com