title: Getting an Exception / ANR with greenDAO
body: <p>I have a huge problem! Some people that are using my app are getting an ANR (app is not responding), when they are doing a database operation (like updating an Object to the database), while an (intent-)service with database reading is running. </p>
  
  <p><strong>In detail:</strong></p>
  
  <p>I am using a single-instance pattern with the Application-Desgin. That means the given context to the SQLiteOpenHelper is the ApplicationContext
  the block operations are:</p>
  
  <pre><code>ArrayList&lt;Workposition&gt; web_list = (ArrayList&lt;Workposition&gt;) sessionDAO
                      .getWorkpositionDao().queryBuilder().list();
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>sessionDAO.getWorkpositionDao().update(plantevent);
  </code></pre>
  
  <p>The both sessionDao using the a SQLLiteHelper with the ApplicationContext. The first read operation is happening in the background and the second operation happens at an onClick method</p>
  
  <p>if you are interested in reading the ANR there you go, but the most important stuff is listed above.
  The code lines mentioned above are in EventView and in Workposition.</p>
  
  <pre><code>    ----- pid 23262 at 2014-10-21 07:58:59 -----
  Cmd line: de.myApp
  
  JNI: CheckJNI is off; workarounds are 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
  at java.lang.Object.wait(Native Method)
  - waiting on &lt;0x41806f70&gt; (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:157)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:846)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1175)
  at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:180)
  at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:256)
  at de.greenrobot.dao.identityscope.IdentityScopeLong.put2(IdentityScopeLong.java:85)
  at de.greenrobot.dao.identityscope.IdentityScopeLong.put(IdentityScopeLong.java:76)
  at de.greenrobot.dao.identityscope.IdentityScopeLong.put(IdentityScopeLong.java:31)
  at de.greenrobot.dao.AbstractDao.attachEntity(AbstractDao.java:695)
  at de.greenrobot.dao.AbstractDao.updateInsideSynchronized(AbstractDao.java:680)
  at de.greenrobot.dao.AbstractDao.update(AbstractDao.java:654)
  at de.myApp.views.EventView$1.run(EventView.java:122)
  at android.os.Handler.handleCallback(Handler.java:733)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:157)
  at android.app.ActivityThread.main(ActivityThread.java:5356)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
  at 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
  at java.lang.Object.wait(Native Method)
  - waiting on &lt;0x42c4b8f8&gt; (a java.lang.VMThread) held by tid=13 (IntentService[a])
  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:197)
  at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:739)
  at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:400)
  at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:905)
  at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
  at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
  at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:152)
  at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:124)
  at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:214)
  at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
  at de.greenrobot.dao.AbstractDao.loadAllFromCursor(AbstractDao.java:392)
  at de.greenrobot.dao.AbstractDao.loadAllAndCloseCursor(AbstractDao.java:184)
  at de.greenrobot.dao.InternalQueryDaoAccess.loadAllAndCloseCursor(InternalQueryDaoAccess.java:21)
  at de.greenrobot.dao.query.Query.list(Query.java:121)
  at de.greenrobot.dao.query.QueryBuilder.list(QueryBuilder.java:374)
  at de.myApp.modelDAO.Workposition.upload(Workposition.java:588)
  at de.myApp.service.ApiService.update(ApiService.java:138)
  at de.myApp.service.ApiService.onHandleIntent(ApiService.java:51)
  at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:157)
  at 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)
  at 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
  at java.lang.Object.wait(Native Method)
  - waiting on &lt;0x42e070d0&gt; (a java.lang.VMThread) held by tid=10 (AsyncTask #1)
  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:157)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2017)
  at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:410)
  at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at 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
  at java.lang.Object.wait(Native Method)
  - waiting on &lt;0x42ca1a28&gt; (a java.lang.VMThread) held by tid=12 (pool-1-thread-1)
  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:157)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2017)
  at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:410)
  at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at 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)
  at dalvik.system.NativeStart.run(Native Method)
  </code></pre>
  
  <p>I have no idea why this problem apears. Is it because of the single-instance? would it work if i would use two different contexts? or should i execute update in an background thread?</p>