Android studio 告警信息
Call to 'Thread.sleep()' in a loop, probably busy-waiting
Inspection info: Reports calls to java.lang.Thread.sleep() that occur inside loops. Such calls are indicative of "busy-waiting". Busy-waiting is often inefficient, and may result in unexpected deadlocks as busy-waiting threads do not release locked resources.
解决办法:替换为Timer及ScheduledExecutorService方案实现线程时长频率
问题分析

从代码中可以看到,告警位置特诊为循环中使用Thread.sleep(),且传入参数较短,
我们尝试去掉循环效果如下

可以看到黄色代码报警标志已经消失。
博客围绕Android Studio告警信息展开,指出告警位置特征为循环中使用Thread.sleep()且传入参数较短。解决办法是替换为Timer及ScheduledExecutorService方案实现线程时长频率,去掉循环后黄色代码报警标志消失。

2万+

被折叠的 条评论
为什么被折叠?



