有什么想法吗,为什么这部分代码会锁定 UI 线程?
synchronized (executionMonitor) {
thread = new Thread(asyncCommand);
thread.setPriority(Thread.MIN_PRIORITY);
thread.setName(command.getClass().getSimpleName());
thread.start();
return;
}
我正在从 UI block 启动线程。在调试过程中我发现,UI 线程处于 MONITOR 状态。但我不明白为什么?
executionMonitor 仅定义为对象:
private Object executionMonitor = new Object();
并且未在其他地方使用。
最佳答案
尝试在同步块(synchronized block)之外返回。
更新:
确认不是解决方案 - 即使 return 语句位于同步块(synchronized block)内,Java 也会自动释放锁
关于java - Android - 从同步块(synchronized block)启动线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34393119/