我的开发控制台中出现了ANR错误报告。我是否需要在我的服务中从onSignalStrengthsChanged
生成一个工作线程来停止ANR以进行长sql查询?
我也无法判断这是否是互斥锁,但我只通过ContentProvider
访问我的数据库。
这是长查询的ANR还是互斥锁ANR?
DALVIK THREADS :(互斥:tll = 0 tsl = 0 tscl = 0 ghl = 0 hwl = 0 hwll = 0) “main”prio = 5 tid = 1 NATIVE | group =“main”sCount = 1 dsCount = 0 obj = 0x4002a278 self = 0xcf50 | sysTid = 9149 nice = 0 sched = 0/0
at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1582)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426)
at kenyu73.realsignal.DatabaseProvider.insert(DatabaseProvider.java:55)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:198)
at android.content.ContentResolver.insert(ContentResolver.java:618)
at kenyu73.realsignal.DatabaseWrapper.insert(DatabaseWrapper.java:189)
at kenyu73.realsignal.SignalStats.updateDbStats(SignalStats.java:154)
at kenyu73.realsignal.SignalStats.updateSignalStats(SignalStats.java:116)
at kenyu73.realsignal.RealSignalService$2.onSignalStrengthsChanged(RealSignalService.java:156)
at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3695)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
内容提供者查询默认在ui线程中运行,因此建议创建一个新线程来进行查询工作。
此外,mutex lock
在尝试获取已锁定的锁时将使用次数,但如果只有一个线程,则可能不需要锁定。