Android Call to ‘Thread.sleep()‘ in a loop, probably busy-waiting Inspection info:
告警信息Call to 'Thread.sleep()' in a loop, probably busy-waitingInspection info: Reports calls to java.lang.Thread.sleep() that occur inside loops. Such calls are indicative of "busy-waiting". Busy-waiti
·
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(),且传入参数较短,
我们尝试去掉循环效果如下
可以看到黄色代码报警标志已经消失。
更多推荐
已为社区贡献2条内容
所有评论(0)