title: Android ANR: thread waiting on lock that it already holds?
body: <p>I'm seeing an ANR in my Android application. The stack of my main thread shows this happens while it is running a DB query. As per the <a href="http://developer.android.com/training/articles/perf-anr.html" rel="nofollow">Keeping your app responsive</a> guidelines, this is probably wrong and should be moved to a worker thread.</p>
  
  <p>However, I want to check that this operation is just slow and not deadlocked. What I'm confused by, is the stack shows this thread <code>tid=1</code> is waiting for <code>&lt;0x41788f70&gt;</code>, which is held by ... <code>tid=1</code>! <b>How is this possible?</b> Surely if it is this thread holding the object, there's no need to wait? What am I missing here?</p>
  
  <p>I can't find any other reference to the handle <code>&lt;0x41788f70&gt;</code> anywhere else in the stack dump.</p>
  
  <p>Thanks for your help.</p>
  
  <p>Here's the stack of the main thread:</p>
  
  <pre><code>"main" prio=5 tid=1 TIMED_WAIT
    | group="main" sCount=1 dsCount=0 obj=0x41788ea0 self=0x41677588
    | sysTid=19868 nice=-11 sched=0/0 cgrp=apps handle=1074336084
    | state=S schedstat=( 530094727 210277810 1460 ) utm=36 stm=17 core=1
    at java.lang.Object.wait(Native Method)
    - waiting on &lt;0x41788f70&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.parkNanos(LockSupport.java:197)
    at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:735)
    at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:397)
    at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:905)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:586)
    at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
    at android.database.sqlite.SQLiteStatement.&lt;init&gt;(SQLiteStatement.java:31)
    at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1126)
  ...
    at android.os.Looper.loop(Looper.java:136)
  </code></pre>