2013-10-16 111 views
0

我在我的應用程序中有一個BroadcastReceiver,每隔X秒由一個ALARM_SERVICE調用。這個BroadcastReceiver調用另一個由AsyncTask運行的服務(爲了避免阻塞主線程),但我收到了一些來自我的用戶的ANR以及谷歌提供給我的日誌,我無法閱讀它,誠實。ANR廣播的意圖

有人可以幫我理解日誌並解決問題嗎?

這是111頁的日誌,谷歌給我:

DALVIK線程: (互斥:TLL = 0 TSL = 0 TSCL = 0 GHL = 0)

"main" prio=5 tid=1 WAIT 
| group="main" sCount=1 dsCount=0 obj=0x418c8578 self=0x4179e1c0 
| sysTid=24081 nice=0 sched=0/0 cgrp=apps handle=1074630652 
| state=S schedstat=(0 0 0) utm=1049 stm=265 core=0 
at java.lang.Object.wait(Native Method) 
- waiting on <0x418c8978> (a java.lang.VMThread) held by tid=1 (main) 
at java.lang.Thread.parkFor(Thread.java:1205) 
at sun.misc.Unsafe.park(Unsafe.java:325) 
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:159) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:810) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:843) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1173) 
at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:183) 
at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:259) 
at android.view.SurfaceView.updateWindow(SurfaceView.java:499) 
at android.view.SurfaceView.access$000(SurfaceView.java:86) 
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175) 
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:833) 
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1860) 
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004) 
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481) 
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 
at android.view.Choreographer.doCallbacks(Choreographer.java:562) 
at android.view.Choreographer.doFrame(Choreographer.java:532) 
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 

"Thread-7562" prio=5 tid=25 TIMED_WAIT 
| group="main" sCount=1 dsCount=0 obj=0x426ab1b0 self=0x58b6f030 
| sysTid=26080 nice=0 sched=0/0 cgrp=apps handle=1488405504 
| state=S schedstat=(0 0 0) utm=0 stm=0 core=1 
at java.lang.Object.wait(Native Method) 
- waiting on <0x426ab370> (a java.lang.VMThread) held by tid=25 (Thread-7562) 
at java.lang.Thread.parkFor(Thread.java:1205) 
at sun.misc.Unsafe.park(Unsafe.java:325) 
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:199) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2058) 
at com.package.util.VRBlockingHolder.poll(VRBlockingHolder.java:85) 
at com.package.util.VRBlockingIndicator.isActive(VRBlockingIndicator.java:42) 
at com.package.packagename.VRBackgroundTaskRunner$OneThread.run(VRBackgroundTaskRunner.java:82) 

"Thread-7561" prio=5 tid=24 TIMED_WAIT 
| group="main" sCount=1 dsCount=0 obj=0x42a3b5a0 self=0x4177f188 
| sysTid=26079 nice=0 sched=0/0 cgrp=apps handle=1488942696 
| state=S schedstat=(0 0 0) utm=0 stm=0 core=1 
at java.lang.Object.wait(Native Method) 
- waiting on <0x42a3b6e0> (a java.lang.VMThread) held by tid=24 (Thread-7561) 
at java.lang.Thread.parkFor(Thread.java:1205) 
at sun.misc.Unsafe.park(Unsafe.java:325) 
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:199) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2058) 
at com.package.util.VRBlockingHolder.poll(VRBlockingHolder.java:85) 
at com.package.util.VRBlockingIndicator.isActive(VRBlockingIndicator.java:42) 
at com.package.packagename.VRBackgroundTaskRunner$OneThread.run(VRBackgroundTaskRunner.java:82) 

"Thread-7514" prio=5 tid=23 TIMED_WAIT 
| group="main" sCount=1 dsCount=0 obj=0x42f6d0b0 self=0x57af4b48 
| sysTid=25583 nice=0 sched=0/0 cgrp=apps handle=1471220936 
| state=S schedstat=(0 0 0) utm=2825 stm=1344 core=1 
at java.lang.Object.wait(Native Method) 
- waiting on <0x42680658> (a java.lang.VMThread) held by tid=23 (Thread-7514) 
at java.lang.Thread.parkFor(Thread.java:1205) 
at sun.misc.Unsafe.park(Unsafe.java:325) 
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:199) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2058) 
at com.package.util.VRBlockingHolder.poll(VRBlockingHolder.java:85) 
at com.package.util.VRBlockingIndicator.isActive(VRBlockingIndicator.java:42) 
at com.package.packagename.android.map.VRMapSurfaceView$VRMapSurfaceViewDrawThread.run(VRMapSurfaceView.java:152) 

"Thread-7513" prio=5 tid=21 WAIT 
| group="main" sCount=1 dsCount=0 obj=0x42f6cf90 self=0x5190eb28 
| sysTid=25582 nice=0 sched=0/0 cgrp=apps handle=1373146856 
| state=S schedstat=(0 0 0) utm=0 stm=1 core=0 
at java.lang.Object.wait(Native Method) 
- waiting on <0x421dfbc0> (a java.lang.Object) 
at java.lang.Object.wait(Object.java:364) 
at com.package.packagename.map.VRMapController.waitForNextLoadRequest(VRMapController.java:233) 
at com.package.packagename.map.VRMapImageLoader.run(VRMapImageLoader.java:44) 

"Timer-11" prio=5 tid=22 TIMED_WAIT 
| group="main" sCount=1 dsCount=0 obj=0x42209970 self=0x58dc5440 
| sysTid=25579 nice=0 sched=0/0 cgrp=apps handle=1494663176 
| state=S schedstat=(0 0 0) utm=30 stm=0 core=1 
at java.lang.Object.wait(Native Method) 
- waiting on <0x42209970> (a java.util.Timer$TimerImpl) 
at java.lang.Object.wait(Object.java:401) 
at java.util.Timer$TimerImpl.run(Timer.java:238) 

"Thread-7494" prio=5 tid=20 TIMED_WAIT 
| group="main" sCount=1 dsCount=0 obj=0x42b4fe40 self=0x4179adc8 
| sysTid=25563 nice=0 sched=0/0 cgrp=apps handle=1099057424 
| state=S schedstat=(0 0 0) utm=235 stm=33 core=1 
at java.lang.VMThread.sleep(Native Method) 
at java.lang.Thread.sleep(Thread.java:1013) 
at java.lang.Thread.sleep(Thread.java:995) 
at com.package.packagename.map.VRMapView$LongTasksThread.run(VRMapView.java:2806) 

"Thread-7449" prio=5 tid=18 TIMED_WAIT 
| group="main" sCount=1 dsCount=0 obj=0x42b4da70 self=0x591612b8 
| sysTid=25446 nice=0 sched=0/0 cgrp=apps handle=1494619912 
| state=S schedstat=(0 0 0) utm=579 stm=400 core=1 
at java.lang.Object.wait(Native Method) 
- waiting on <0x42b4db70> (a java.lang.VMThread) held by tid=18 (Thread-7449) 
at java.lang.Thread.parkFor(Thread.java:1205) 
at sun.misc.Unsafe.park(Unsafe.java:325) 
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:199) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2058) 
at com.package.util.VRBlockingHolder.poll(VRBlockingHolder.java:85) 
at com.package.util.VRBlockingIndicator.isActive(VRBlockingIndicator.java:42) 
at com.package.packagename.VRBackgroundTaskRunner$OneThread.run(VRBackgroundTaskRunner.java:82) 

"Thread-7354" prio=5 tid=19 WAIT 
| group="main" sCount=1 dsCount=0 obj=0x421f0330 self=0x51d8c7e0 
| sysTid=24637 nice=0 sched=0/0 cgrp=apps handle=1074503688 
| state=S schedstat=(0 0 0) utm=24 stm=3 core=0 
at java.lang.Object.wait(Native Method) 
- waiting on <0x421f04a0> (a java.lang.Object) 
at java.lang.Object.wait(Object.java:364) 
at com.package.packagename.map.VRHeightMapLoadThread.run(VRHeightMapLoadThread.java:113) 

"Binder_3" prio=5 tid=17 NATIVE 
| group="main" sCount=1 dsCount=0 obj=0x421ecb00 self=0x51d868b0 
| sysTid=24493 nice=0 sched=0/0 cgrp=apps handle=1074208152 
| state=S schedstat=(0 0 0) utm=139 stm=69 core=1 
#00 pc 0001b300 /system/lib/libc.so (__ioctl+8) 
#01 pc 0002b91b /system/lib/libc.so (ioctl+14) 
#02 pc 0001b539 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+140) 
#03 pc 0001bcd7 /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+154) 
#04 pc 0001fae9 /system/lib/libbinder.so 
#05 pc 00011a8d /system/lib/libutils.so (android::Thread::_threadLoop(void*)+216) 
#06 pc 0004b631 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+68) 
#07 pc 00011581 /system/lib/libutils.so 
#08 pc 0000ca58 /system/lib/libc.so (__thread_entry+72) 
#09 pc 0000cbd4 /system/lib/libc.so (pthread_create+208) 
at dalvik.system.NativeStart.run(Native Method) 

"AsyncTask #5" prio=5 tid=16 WAIT 
| group="main" sCount=1 dsCount=0 obj=0x421dacb8 self=0x51dd65c8 
| sysTid=24481 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1373465112 
| state=S schedstat=(0 0 0) utm=3 stm=0 core=1 
at java.lang.Object.wait(Native Method) 
- waiting on <0x421dae10> (a java.lang.VMThread) held by tid=16 (AsyncTask #5) 
at java.lang.Thread.parkFor(Thread.java:1205) 
at sun.misc.Unsafe.park(Unsafe.java:325) 
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:159) 
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2019) 
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413) 
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1013) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1073) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
at java.lang.Thread.run(Thread.java:841) 

"[email protected]@4216db88" 

守護進程prio = 5 tid = 15等待 | group =「main」sCount = 1 dsCount = 0 obj = 0x4216e7e0 self = 0x400b6a18 | sysTid = 24414 nice = 0 sched = 0/0 cgrp = apps handle = 1074723664 |狀態= S schedstat =(0 0 0)UTM = 0 STM = 0核心= 1 在java.lang.Object.wait(本機方法) - 等待< 0x421b5820 ...

回答

0

當報警是解僱,然後檢查服務是否運行。如果它正在運行,那麼跳過或如果沒有,那麼做同樣的工作,你正在工作。 檢查服務的代碼是否運行:

private boolean isMyServiceRunning(){ ActivityManager manager =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); (RunningServiceInfo service:manager.getRunningServices(Integer.MAX_VALUE)){ if(MyService.class.getName()。equals(service.service.getClassName())){ return true; } } return false; }

可能是,你開始這麼多的服務。

+0

讓我試試。雖然我無法自己測試它,因爲我無法複製該錯誤..任何想法如何讀取ARN代碼? – Davidjburgos

+0

再次看我的代碼我認爲是線程之間的併發情況..查看ANR我可以看到主線程正在等待另一個線程..這可能是因爲在我調用服務之前,我調用了一個同步函數,所以也許這會讓這個線程等待另一個線程。 – Davidjburgos

0

我有同樣的問題,如果你使用兩個線程出現問題:

從一個線程(例如:的AsyncTask)首先運行:

  1. disableAutoCommit
  2. 一個SQLiteException發生!
  3. restoreAutocommit不叫!!!

然後嘗試從其他線程(例如:UI線程)使用dao - >它將永久等待,因爲從第一個任務中缺少restoreAutocommit - >這會導致ANR!

的解決方案是:增加一個最後restoreAutocommit

例如:

boolean prev = entityDao.disableAutoCommit(); 
    try 
    { 
     entityDao.disableAutoCommit(); 
     storeData(data);// if an Exception occurs -> finally is also called 
    } 
    finally 
    { 
     entityDao.restoreAutocommit(prev); 
    }