Android While 循环导致的资源占用过高进而导致程序崩溃问题

Timeline: Activity_launch_request time:65620
04-14 15:31:25.347: I/dalvikvm(3483): Total arena pages for JIT: 11
04-14 15:31:25.621: D/dalvikvm(3483): JIT unchain all for threadid=13
04-14 15:31:26.371: W/dalvikvm(3483): threadid=1: spin on suspend #1 threadid=13 (pcf=0)
04-14 15:31:27.122: W/dalvikvm(3483): threadid=1: spin on suspend #2 threadid=13 (pcf=0)
04-14 15:31:27.122: I/dalvikvm(3483): "main" prio=5 tid=1 RUNNABLE

 

JIT unchain all for threadid=19

04-14 15:33:28.638: W/dalvikvm(5595): threadid=20: spin on suspend #1 threadid=19 (pcf=0)
04-14 15:33:29.388: W/dalvikvm(5595): threadid=20: spin on suspend #2 threadid=19 (pcf=0)
04-14 15:33:29.388: I/dalvikvm(5595): "pool-5-thread-2" prio=5 tid=20 RUNNABLE

 

运行应用过程中多次调用While(!isComplete); 对线程进行阻塞,导致线程资源占用过高。修改为一下实现方式可以降低资源占用

while(!isComplete){

  try {

    Thread.sleep(100);
  } catch (InterruptedException e) {
  // TODO Auto-generated catch block
    Log.e(e);
  }
  continue;

}

 

posted @ 2016-04-14 16:51  蓝色冰晶  阅读(1580)  评论(0编辑  收藏  举报