android - Getting an Exception / ANR with greenDAO -
i have huge problem! people using app getting anr (app not responding), when doing database operation (like updating object database), while (intent-)service database reading running.
in detail:
i using single-instance pattern application-desgin. means given context sqliteopenhelper applicationcontext block operations are:
arraylist<workposition> web_list = (arraylist<workposition>) sessiondao .getworkpositiondao().querybuilder().list();
and
sessiondao.getworkpositiondao().update(plantevent);
the both sessiondao using sqllitehelper applicationcontext. first read operation happening in background , sec operation happens @ onclick method
if interested in reading anr there go, of import stuff listed above. code lines mentioned above in eventview , in workposition.
----- pid 23262 @ 2014-10-21 07:58:59 ----- cmd line: de.myapp jni: checkjni off; workarounds off; pins=0; globals=293 dalvik threads: (mutexes: tll=0 tsl=0 tscl=0 ghl=0) "main" prio=5 tid=1 wait | group="main" scount=1 dscount=0 obj=0x41806ea0 self=0x416fcb78 | systid=23262 nice=0 sched=0/0 cgrp=apps handle=1073869140 | state=s schedstat=( 0 0 0 ) utm=306 stm=55 core=1 @ java.lang.object.wait(native method) - waiting on <0x41806f70> (a java.lang.vmthread) held tid=1 (main) @ java.lang.thread.parkfor(thread.java:1205) @ sun.misc.unsafe.park(unsafe.java:325) @ java.util.concurrent.locks.locksupport.park(locksupport.java:157) @ java.util.concurrent.locks.abstractqueuedsynchronizer.parkandcheckinterrupt(abstractqueuedsynchronizer.java:813) @ java.util.concurrent.locks.abstractqueuedsynchronizer.acquirequeued(abstractqueuedsynchronizer.java:846) @ java.util.concurrent.locks.abstractqueuedsynchronizer.acquire(abstractqueuedsynchronizer.java:1175) @ java.util.concurrent.locks.reentrantlock$nonfairsync.lock(reentrantlock.java:180) @ java.util.concurrent.locks.reentrantlock.lock(reentrantlock.java:256) @ de.greenrobot.dao.identityscope.identityscopelong.put2(identityscopelong.java:85) @ de.greenrobot.dao.identityscope.identityscopelong.put(identityscopelong.java:76) @ de.greenrobot.dao.identityscope.identityscopelong.put(identityscopelong.java:31) @ de.greenrobot.dao.abstractdao.attachentity(abstractdao.java:695) @ de.greenrobot.dao.abstractdao.updateinsidesynchronized(abstractdao.java:680) @ de.greenrobot.dao.abstractdao.update(abstractdao.java:654) @ de.myapp.views.eventview$1.run(eventview.java:122) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:157) @ android.app.activitythread.main(activitythread.java:5356) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1265) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1081) @ dalvik.system.nativestart.main(native method) "intentservice[a]" prio=5 tid=13 timed_wait | group="main" scount=1 dscount=0 obj=0x42e28460 self=0x7b5302c0 | systid=23337 nice=0 sched=0/0 cgrp=apps handle=2005620856 | state=s schedstat=( 0 0 0 ) utm=7309 stm=180 core=0 @ java.lang.object.wait(native method) - waiting on <0x42c4b8f8> (a java.lang.vmthread) held tid=13 (intentservice[a]) @ java.lang.thread.parkfor(thread.java:1205) @ sun.misc.unsafe.park(unsafe.java:325) @ java.util.concurrent.locks.locksupport.parknanos(locksupport.java:197) @ android.database.sqlite.sqliteconnectionpool.waitforconnection(sqliteconnectionpool.java:739) @ android.database.sqlite.sqliteconnectionpool.acquireconnection(sqliteconnectionpool.java:400) @ android.database.sqlite.sqlitesession.acquireconnection(sqlitesession.java:905) @ android.database.sqlite.sqlitesession.executeforcursorwindow(sqlitesession.java:834) @ android.database.sqlite.sqlitequery.fillwindow(sqlitequery.java:62) @ android.database.sqlite.sqlitecursor.fillwindow(sqlitecursor.java:152) @ android.database.sqlite.sqlitecursor.onmove(sqlitecursor.java:124) @ android.database.abstractcursor.movetoposition(abstractcursor.java:214) @ android.database.abstractcursor.movetonext(abstractcursor.java:245) @ de.greenrobot.dao.abstractdao.loadallfromcursor(abstractdao.java:392) @ de.greenrobot.dao.abstractdao.loadallandclosecursor(abstractdao.java:184) @ de.greenrobot.dao.internalquerydaoaccess.loadallandclosecursor(internalquerydaoaccess.java:21) @ de.greenrobot.dao.query.query.list(query.java:121) @ de.greenrobot.dao.query.querybuilder.list(querybuilder.java:374) @ de.myapp.modeldao.workposition.upload(workposition.java:588) @ de.myapp.service.apiservice.update(apiservice.java:138) @ de.myapp.service.apiservice.onhandleintent(apiservice.java:51) @ android.app.intentservice$servicehandler.handlemessage(intentservice.java:65) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:157) @ android.os.handlerthread.run(handlerthread.java:61) "binder_3" prio=5 tid=11 native | group="main" scount=1 dscount=0 obj=0x42fc7e68 self=0x778c0300 | systid=23306 nice=0 sched=0/0 cgrp=apps handle=2006715504 | state=s schedstat=( 0 0 0 ) utm=0 stm=0 core=1 #00 pc 0002072c /system/lib/libc.so (__ioctl+8) #01 pc 0002cec3 /system/lib/libc.so (ioctl+14) #02 pc 0001d3ed /system/lib/libbinder.so (android::ipcthreadstate::talkwithdriver(bool)+140) #03 pc 0001daf7 /system/lib/libbinder.so (android::ipcthreadstate::getandexecutecommand()+6) #04 pc 0001db8d /system/lib/libbinder.so (android::ipcthreadstate::jointhreadpool(bool)+48) #05 pc 000219e9 /system/lib/libbinder.so #06 pc 0000ea5d /system/lib/libutils.so (android::thread::_threadloop(void*)+216) #07 pc 00052299 /system/lib/libandroid_runtime.so (android::androidruntime::javathreadshell(void*)+68) #08 pc 0000e58f /system/lib/libutils.so #09 pc 0000d278 /system/lib/libc.so (__thread_entry+72) #10 pc 0000d410 /system/lib/libc.so (pthread_create+240) @ dalvik.system.nativestart.run(native method) "asynctask #1" prio=5 tid=10 wait | group="main" scount=1 dscount=0 obj=0x42e06f38 self=0x778c2768 | systid=23301 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=2005674944 | state=s schedstat=( 0 0 0 ) utm=29 stm=5 core=2 @ java.lang.object.wait(native method) - waiting on <0x42e070d0> (a java.lang.vmthread) held tid=10 (asynctask #1) @ java.lang.thread.parkfor(thread.java:1205) @ sun.misc.unsafe.park(unsafe.java:325) @ java.util.concurrent.locks.locksupport.park(locksupport.java:157) @ java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject.await(abstractqueuedsynchronizer.java:2017) @ java.util.concurrent.linkedblockingqueue.take(linkedblockingqueue.java:410) @ java.util.concurrent.threadpoolexecutor.gettask(threadpoolexecutor.java:1035) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1097) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:841) "pool-1-thread-1" prio=5 tid=12 wait | group="main" scount=1 dscount=0 obj=0x42ca18e0 self=0x79564280 | systid=23281 nice=0 sched=0/0 cgrp=apps handle=2035697368 | state=s schedstat=( 0 0 0 ) utm=1 stm=1 core=2 @ java.lang.object.wait(native method) - waiting on <0x42ca1a28> (a java.lang.vmthread) held tid=12 (pool-1-thread-1) @ java.lang.thread.parkfor(thread.java:1205) @ sun.misc.unsafe.park(unsafe.java:325) @ java.util.concurrent.locks.locksupport.park(locksupport.java:157) @ java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject.await(abstractqueuedsynchronizer.java:2017) @ java.util.concurrent.linkedblockingqueue.take(linkedblockingqueue.java:410) @ java.util.concurrent.threadpoolexecutor.gettask(threadpoolexecutor.java:1035) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1097) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:841) "binder_2" prio=5 tid=9 native | group="main" scount=1 dscount=0 obj=0x42a3f878 self=0x7255dc60 | systid=23273 nice=0 sched=0/0 cgrp=apps handle=1918229016 | state=s schedstat=( 0 0 0 ) utm=0 stm=0 core=0 #00 pc 0002072c /system/lib/libc.so (__ioctl+8) #01 pc 0002cec3 /system/lib/libc.so (ioctl+14) #02 pc 0001d3ed /system/lib/libbinder.so (android::ipcthreadstate::talkwithdriver(bool)+140) #03 pc 0001daf7 /system/lib/libbinder.so (android::ipcthreadstate::getandexecutecommand()+6) #04 pc 0001db8d /system/lib/libbinder.so (android::ipcthreadstate::jointhreadpool(bool)+48) #05 pc 000219e9 /system/lib/libbinder.so #06 pc 0000ea5d /system/lib/libutils.so (android::thread::_threadloop(void*)+216) #07 pc 00052299 /system/lib/libandroid_runtime.so (android::androidruntime::javathreadshell(void*)+68) #08 pc 0000e58f /system/lib/libutils.so #09 pc 0000d278 /system/lib/libc.so (__thread_entry+72) #10 pc 0000d410 /system/lib/libc.so (pthread_create+240) @ dalvik.system.nativestart.run(native method)
i have no thought why problem apears. because of single-instance? work if utilize 2 different contexts? or should execute update in background thread?
you should never access database on main thread. lots of database operations utilize single lock when this, long running background query can block main thread. since background tasks have lower priority, can cause anr. in add-on this, disk access may slowed random reason (e.g. play store updating apps). don't want rely ui on (don't forget, ui has 16 ms).
in anr, background thread has identity scope lock, waiting sqliteconnection while main thread blocked identity scope lock of greenish dao. nil shows why database taking much provide connection (are there other threads not shown in anr?).
just create sure never access database on main thread. (write or read, not matter much). believe scheme solve conflict (e.g. connection available)
android sqlite dao greendao
No comments:
Post a Comment