简体   繁体   English

解释ANR堆栈跟踪

[英]Interpreting an ANR stack trace

I'm working with an implementation of an MQTT client from the PAHO library in Android. 我正在使用Android中PAHO库的MQTT客户端实现。 Sometimes, the application locks up when it tried to publish a message (I think) and I can't figure out what's going on. 有时,应用程序在尝试发布消息时会锁定(我认为)并且我无法弄清楚发生了什么。

I also apologize in advance for the all to long post. 我也提前为所有长篇大论道歉。 I really don't know what the important bits are and the SO "spoiler" tag >! 我真的不知道重要的是什么和SO“扰流板”标签>! wouldn't work to hide the details. 不会隐藏细节。

The MQTT client is working in a separate thread but I'm calling the mqtt client instance from the UI thread. MQTT客户端在单独的线程中工作,但我从UI线程调用mqtt客户端实例。 Perhaps this causes a lockup? 也许这导致锁定? Should I instead define the client as an instance of the thread and call a method in the thread which forwards the action to the client? 我应该将客户端定义为线程的实例,并在线程中调用一个方法将该操作转发给客户端吗?

When the app hangs, after a while ANR kicks in and asks to close the app. 当应用程序挂起时,一段时间ANR开始并要求关闭应用程序。 When I do that I get the following stack trace for my process from /data/anr/traces.txt: 当我这样做时,我从/data/anr/traces.txt获取我的进程的以下堆栈跟踪:

DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0)
"main" prio=5 tid=1 WAIT
  | group="main" sCount=1 dsCount=0 obj=0x40a59460 self=0x109d828
  | sysTid=22050 nice=0 sched=0/0 cgrp=default handle=1074492552
  | schedstat=( 8524633000 459501000 2204 ) utm=827 stm=25 core=1
  at java.lang.Object.wait(Native Method)
  - waiting on <0x410f4bd0> (a java.lang.Object)
  at java.lang.Object.wait(Object.java:364)
  at org.eclipse.paho.client.mqttv3.internal.MqttDeliveryTokenImpl.waitUntilSent(MqttDeliveryTokenImpl.java:120)
  at org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:85)
  at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:118)
  at org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:62)
  at se.chalmers.pd.dashboard.MqttWorker.publish(MqttWorker.java:177)
  at se.chalmers.pd.dashboard.ApplicationController.sendResponse(ApplicationController.java:238)
  at se.chalmers.pd.dashboard.ApplicationController.onLoadComplete(ApplicationController.java:358)
  at se.chalmers.pd.dashboard.MainActivity$CustomWebViewClient.onPageFinished(MainActivity.java:89)
  at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:275)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:4424)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  at dalvik.system.NativeStart.main(Native Method)

"Thread-3645" prio=5 tid=12 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4111a5f8 self=0x13cc698
  | sysTid=22083 nice=0 sched=0/0 cgrp=default handle=19370528
  | schedstat=( 35731000 17350000 70 ) utm=1 stm=2 core=0
  at dalvik.system.NativeStart.run(Native Method)

"MQTT Client Callback" prio=5 tid=17 WAIT
  | group="main" sCount=1 dsCount=0 obj=0x41118bf0 self=0x13bb500
  | sysTid=22082 nice=0 sched=0/0 cgrp=default handle=20691280
  | schedstat=( 392860000 110613000 493 ) utm=35 stm=4 core=1
  at java.lang.Object.wait(Native Method)
  - waiting on <0x410d1c48> (a java.lang.Object)
  at java.lang.Object.wait(Object.java:364)
  at org.eclipse.paho.client.mqttv3.internal.MqttDeliveryTokenImpl.waitUntilSent(MqttDeliveryTokenImpl.java:120)
  at org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:85)
  at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:118)
  at org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:62)
  at se.chalmers.pd.dashboard.MqttWorker.publish(MqttWorker.java:177)
  at se.chalmers.pd.dashboard.ApplicationController.sendResponse(ApplicationController.java:238)
  at se.chalmers.pd.dashboard.ApplicationController.handleSystemMessage(ApplicationController.java:210)
  at se.chalmers.pd.dashboard.ApplicationController.onMessage(ApplicationController.java:154)
  at se.chalmers.pd.dashboard.MqttWorker$1$CustomMqttCallback.notifyCallbacks(MqttWorker.java:133)
  at se.chalmers.pd.dashboard.MqttWorker$1$CustomMqttCallback.messageArrived(MqttWorker.java:128)
  at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:248)
  at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:139)
  at java.lang.Thread.run(Thread.java:856)

"MQTT Client Comms Sender" prio=5 tid=16 TIMED_WAIT
  | group="main" sCount=1 dsCount=0 obj=0x41118ae0 self=0x13bada0
  | sysTid=22081 nice=0 sched=0/0 cgrp=default handle=20689392
  | schedstat=( 6038000 11147000 189 ) utm=0 stm=0 core=0
  at java.lang.Object.wait(Native Method)
  - waiting on <0x410ffd90> (a java.lang.Object)
  at java.lang.Object.wait(Object.java:401)
  at org.eclipse.paho.client.mqttv3.internal.ClientState.get(ClientState.java:555)
  at org.eclipse.paho.client.mqttv3.internal.CommsSender.run(CommsSender.java:83)
  at java.lang.Thread.run(Thread.java:856)

"MQTT Client Comms Receiver" prio=5 tid=15 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x41116048 self=0x13ba870
  | sysTid=22080 nice=0 sched=0/0 cgrp=default handle=20619056
  | schedstat=( 656144000 184252000 2369 ) utm=59 stm=6 core=1
  at libcore.io.Posix.recvfromBytes(Native Method)
  at libcore.io.Posix.recvfrom(Posix.java:131)
  at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
  at libcore.io.IoBridge.recvfrom(IoBridge.java:503)
  at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
  at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
  at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
  at libcore.io.Streams.readSingleByte(Streams.java:41)
  at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:236)
  at java.io.DataInputStream.readByte(DataInputStream.java:96)
  at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:51)
  at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:86)
  at java.lang.Thread.run(Thread.java:856)

"CookieSyncManager" prio=5 tid=14 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x410d0ad0 self=0x1286e20
  | sysTid=22066 nice=10 sched=0/0 cgrp=bg_non_interactive handle=19445224
  | schedstat=( 562000 10095000 5 ) utm=0 stm=0 core=0
  at android.os.MessageQueue.nativePollOnce(Native Method)
  at android.os.MessageQueue.next(MessageQueue.java:118)
  at android.os.Looper.loop(Looper.java:118)
  at android.webkit.WebSyncManager.run(WebSyncManager.java:90)
  at android.webkit.CookieSyncManager.run(CookieSyncManager.java:61)
  at java.lang.Thread.run(Thread.java:856)

"AsyncTask #1" prio=5 tid=13 WAIT
  | group="main" sCount=1 dsCount=0 obj=0x410d0920 self=0x121f5b0
  | sysTid=22065 nice=10 sched=0/0 cgrp=bg_non_interactive handle=19335920
  | schedstat=( 5753000 108824000 12 ) utm=0 stm=0 core=0
  at java.lang.Object.wait(Native Method)
  - waiting on <0x410d0ab8> (a java.lang.VMThread) held by tid=13 (AsyncTask #1)
  at java.lang.Thread.parkFor(Thread.java:1231)
  at sun.misc.Unsafe.park(Unsafe.java:323)
  at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
  at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
  at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1009)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1069)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  at java.lang.Thread.run(Thread.java:856)

"WebViewCoreThread" prio=5 tid=11 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x410caa38 self=0x1266550
  | sysTid=22063 nice=0 sched=0/0 cgrp=default handle=18808064
  | schedstat=( 273871000 128721000 264 ) utm=20 stm=7 core=0
  at android.os.MessageQueue.nativePollOnce(Native Method)
  at android.os.MessageQueue.next(MessageQueue.java:118)
  at android.os.Looper.loop(Looper.java:118)
  at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:728)
  at java.lang.Thread.run(Thread.java:856)

"Binder Thread #2" prio=5 tid=10 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x410c1ef0 self=0x129de58
  | sysTid=22062 nice=0 sched=0/0 cgrp=default handle=19025912
  | schedstat=( 1983000 23992000 8 ) utm=0 stm=0 core=1
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #1" prio=5 tid=9 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x410ba370 self=0x127cc90
  | sysTid=22061 nice=0 sched=0/0 cgrp=default handle=18949528
  | schedstat=( 2932000 32665000 18 ) utm=0 stm=0 core=0
  at dalvik.system.NativeStart.run(Native Method)

"FinalizerWatchdogDaemon" daemon prio=5 tid=8 TIMED_WAIT
  | group="main" sCount=1 dsCount=0 obj=0x410b6320 self=0x1227790
  | sysTid=22059 nice=0 sched=0/0 cgrp=default handle=19405328
  | schedstat=( 3721000 6943000 27 ) utm=0 stm=0 core=0
  at java.lang.VMThread.sleep(Native Method)
  at java.lang.Thread.sleep(Thread.java:1031)
  at java.lang.Thread.sleep(Thread.java:1013)
  at java.lang.Daemons$FinalizerWatchdogDaemon.run(Daemons.java:213)
  at java.lang.Thread.run(Thread.java:856)

"FinalizerDaemon" daemon prio=5 tid=7 WAIT
  | group="main" sCount=1 dsCount=0 obj=0x410b61c8 self=0x12207b8
  | sysTid=22058 nice=0 sched=0/0 cgrp=default handle=19405208
  | schedstat=( 1055000 601000 7 ) utm=0 stm=0 core=1
  at java.lang.Object.wait(Native Method)
  - waiting on <0x40a4f5d0> (a java.lang.ref.ReferenceQueue)
  at java.lang.Object.wait(Object.java:401)
  at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102)
  at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73)
  at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
  at java.lang.Thread.run(Thread.java:856)

"ReferenceQueueDaemon" daemon prio=5 tid=6 WAIT
  | group="main" sCount=1 dsCount=0 obj=0x410b6060 self=0x129d168
  | sysTid=22057 nice=0 sched=0/0 cgrp=default handle=19404976
  | schedstat=( 573000 395000 11 ) utm=0 stm=0 core=1
  at java.lang.Object.wait(Native Method)
  - waiting on <0x40a4f4f8> 
  at java.lang.Object.wait(Object.java:364)
  at java.lang.Daemons$ReferenceQueueDaemon.run(Daemons.java:128)
  at java.lang.Thread.run(Thread.java:856)

"Compiler" daemon prio=5 tid=5 VMWAIT
  | group="system" sCount=1 dsCount=0 obj=0x410b5f70 self=0x127c4d0
  | sysTid=22056 nice=0 sched=0/0 cgrp=default handle=19172728
  | schedstat=( 151015000 59330000 862 ) utm=9 stm=6 core=0
  at dalvik.system.NativeStart.run(Native Method)

"JDWP" daemon prio=5 tid=4 VMWAIT
  | group="system" sCount=1 dsCount=0 obj=0x410b5e88 self=0x12b39c8
  | sysTid=22055 nice=0 sched=0/0 cgrp=default handle=19323736
  | schedstat=( 4263000 2800000 18 ) utm=0 stm=0 core=1
  at dalvik.system.NativeStart.run(Native Method)

"Signal Catcher" daemon prio=5 tid=3 RUNNABLE
  | group="system" sCount=0 dsCount=0 obj=0x410b5d90 self=0x1268fd8
  | sysTid=22054 nice=0 sched=0/0 cgrp=default handle=19014912
  | schedstat=( 3760000 203000 4 ) utm=0 stm=0 core=1
  at dalvik.system.NativeStart.run(Native Method)

"GC" daemon prio=5 tid=2 VMWAIT
  | group="system" sCount=1 dsCount=0 obj=0x410b5cb0 self=0x12257d8
  | sysTid=22053 nice=0 sched=0/0 cgrp=default handle=19042944
  | schedstat=( 271726000 42594000 230 ) utm=26 stm=1 core=1
  at dalvik.system.NativeStart.run(Native Method)

----- end 22050 -----

I've turned on strict mode and I do get some traces where it warns about disk writes but none of them are particulary long. 我已经开启了严格模式,我确实得到了一些警告磁盘写入的痕迹,但没有一个特别长。 These are the strict mode traces: 这些是严格的模式跟踪:

> >  04-30 10:29:50.053: D/StrictMode(22229): StrictMode policy violation;
> > ~duration=35 ms: android.os.StrictMode$StrictModeDiskReadViolation:
> > policy=31 violation=2 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1089)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > libcore.io.BlockGuardOs.open(BlockGuardOs.java:106) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > libcore.io.IoBridge.open(IoBridge.java:390) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > java.io.FileOutputStream.(FileOutputStream.java:88) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.io.FileOutputStream.(FileOutputStream.java:73) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence.put(MqttDefaultFilePersistence.java:162)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientState.send(ClientState.java:397)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:81)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:118)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:62)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MqttWorker.publish(MqttWorker.java:177) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.sendResponse(ApplicationController.java:238)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.onLoadComplete(ApplicationController.java:358)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MainActivity$CustomWebViewClient.onPageFinished(MainActivity.java:95)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:275)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.Handler.dispatchMessage(Handler.java:99) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > android.os.Looper.loop(Looper.java:137) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > android.app.ActivityThread.main(ActivityThread.java:4424) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invokeNative(Native Method) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invoke(Method.java:511) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > dalvik.system.NativeStart.main(Native Method) 04-30 10:29:50.053:
> 
> 
> > D/StrictMode(22229): StrictMode policy violation; ~duration=26 ms:
> > android.os.StrictMode$StrictModeDiskWriteViolation: policy=31
> > violation=1 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1063)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > libcore.io.BlockGuardOs.write(BlockGuardOs.java:190) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > libcore.io.IoBridge.write(IoBridge.java:447) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > java.io.FileOutputStream.write(FileOutputStream.java:187) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence.put(MqttDefaultFilePersistence.java:163)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientState.send(ClientState.java:397)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:81)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:118)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:62)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MqttWorker.publish(MqttWorker.java:177) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.sendResponse(ApplicationController.java:238)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.onLoadComplete(ApplicationController.java:358)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MainActivity$CustomWebViewClient.onPageFinished(MainActivity.java:95)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:275)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.Handler.dispatchMessage(Handler.java:99) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > android.os.Looper.loop(Looper.java:137) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > android.app.ActivityThread.main(ActivityThread.java:4424) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invokeNative(Native Method) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invoke(Method.java:511) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > dalvik.system.NativeStart.main(Native Method) 04-30 10:29:50.053:
> 
> 
> > D/StrictMode(22229): StrictMode policy violation; ~duration=18 ms:
> > android.os.StrictMode$StrictModeDiskWriteViolation: policy=31
> > violation=1 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1063)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > libcore.io.BlockGuardOs.write(BlockGuardOs.java:190) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > libcore.io.IoBridge.write(IoBridge.java:447) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > java.io.FileOutputStream.write(FileOutputStream.java:187) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence.put(MqttDefaultFilePersistence.java:165)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientState.send(ClientState.java:397)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:81)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:118)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:62)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MqttWorker.publish(MqttWorker.java:177) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.sendResponse(ApplicationController.java:238)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.onLoadComplete(ApplicationController.java:358)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MainActivity$CustomWebViewClient.onPageFinished(MainActivity.java:95)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:275)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.Handler.dispatchMessage(Handler.java:99) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > android.os.Looper.loop(Looper.java:137) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > android.app.ActivityThread.main(ActivityThread.java:4424) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invokeNative(Native Method) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invoke(Method.java:511) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > dalvik.system.NativeStart.main(Native Method) 04-30 10:29:50.053:
> 
> 
> > D/StrictMode(22229): StrictMode policy violation; ~duration=2 ms:
> > android.os.StrictMode$StrictModeDiskWriteViolation: policy=31
> > violation=1 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1063)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:96) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.io.FileDescriptor.sync(FileDescriptor.java:71) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence.put(MqttDefaultFilePersistence.java:167)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientState.send(ClientState.java:397)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:81)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:118)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:62)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MqttWorker.publish(MqttWorker.java:177) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.sendResponse(ApplicationController.java:238)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.ApplicationController.onLoadComplete(ApplicationController.java:358)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > se.chalmers.pd.dashboard.MainActivity$CustomWebViewClient.onPageFinished(MainActivity.java:95)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:275)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > android.os.Handler.dispatchMessage(Handler.java:99) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > android.os.Looper.loop(Looper.java:137) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > android.app.ActivityThread.main(ActivityThread.java:4424) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invokeNative(Native Method) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > java.lang.reflect.Method.invoke(Method.java:511) 04-30 10:29:50.053:
> > D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
> > 04-30 10:29:50.053: D/StrictMode(22229): at
> > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-30
> > 10:29:50.053: D/StrictMode(22229): at
> > dalvik.system.NativeStart.main(Native Method)

Edit: this is how I enable StrictMode 编辑:这是我启用StrictMode的方式

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
        .detectAll()
        .penaltyLog()
        .build());

Edit 2: for future reference and to add the cause of the issue I figured I should put something in here for the search engines to find. 编辑2:为了将来的参考和添加问题的原因我想我应该在这里放一些东西供搜索引擎查找。

It turned out the problem was with the Node.JS based broker mqttjs we had. 原来问题是我们有基于Node.JS的经纪人mqttjs。 It could just be our implementation, I haven't tested the example from the mqttjs developer. 它可能只是我们的实现,我没有测试mqttjs开发人员的例子。 The broker stopped publishing and returning tokens after a certain number of messages had been published. 在发布了一定数量的消息后,经纪人停止发布并返回令牌。 The MQTT client was running in another thread but since it was called from the UI thread it caused some issues. MQTT客户端在另一个线程中运行,但由于它是从UI线程调用的,因此导致了一些问题。

Anyway, we changed to Mosquitto and now everything is working well. 无论如何,我们改为Mosquitto,现在一切都运转良好。

You're trying to do long running network comms on the UI thread. 您正试图在UI线程上进行长时间运行的网络通信。 This blocks the UI from updating, which is bad. 这会阻止UI更新,这很糟糕。 Android detects this fact and handles it as an ANR. Android检测到这一事实并将其作为ANR处理。

I don't know what bits are your code, but somewhere around here: 我不知道你的代码是什么位,但在这里的某处:

se.chalmers.pd.dashboard.ApplicationController.sendResponse(ApplicationController.java:238)

you should put the MQTT work in a new thread. 你应该把MQTT放在一个新线程中。 If you then need to update the UI as a result of the MQTT work completing, use the Handler. 如果由于MQTT工作完成而需要更新UI,请使用Handler。

As you've enabled the strict mode, you are not allowed to access disk or network while in the UI Thread. 在启用严格模式后,在UI线程中不允许访问磁盘或网络。

Reading your stacktrace, it's obvious that a call to MqttWorker.publish leads to a disk access. 读取堆栈跟踪,很明显,对MqttWorker.publish的调用会导致磁盘访问。 You should put this call in an AsyncTask, or another thread than the UI. 您应该将此调用放在AsyncTask或UI之外的其他线程中。

Your ANR happens in 你的ANR发生在

org.eclipse.paho.client.mqttv3.internal.MqttDeliveryTokenImpl.waitUntilSent

because this method calls Object.wait , probably waiting for another thread to notify it. 因为此方法调用Object.wait ,可能正在等待另一个线程通知它。

Your call is apparently here 你的电话显然在这里

se.chalmers.pd.dashboard.MqttWorker.publish(MqttWorker.java:177)

which is called in your implementation of the WebClient 在您的WebClient实现中调用

se.chalmers.pd.dashboard.MainActivity$CustomWebViewClient.onPageFinished(MainActivity.java:89)

This onPageFinished method is called on the UI thread. 在UI线程上调用此onPageFinished方法。 Calling MqttTopic.publish is a network call and apparently blocks until the call is done. 调用MqttTopic.publish是一个网络调用,显然会阻塞,直到调用完成。 You should put that in a Thread or an AsyncTask so it does not lock the UI Thread. 您应该将它放在Thread或AsyncTask中,这样它就不会锁定UI线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM