Android Call to ‘Thread.sleep()‘ in a loop, probably busy-waiting Inspection info:

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方案实现线程时长频率

问题分析

Android Call to ‘Thread.sleep()‘ in a loop, probably busy-waiting Inspection info:_第1张图片

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

Android Call to ‘Thread.sleep()‘ in a loop, probably busy-waiting Inspection info:_第2张图片
可以看到黄色代码报警标志已经消失。

你可能感兴趣的:(Android,android-studio)