title: Thread automatically going to WAIT state in android
body: <p>I'm starting a new thread in android. What this thread does is that it get output buffers from a MediaCodec then stream them as an flv video to the web browse. I'm having the problem that that background thread is automatically going to wait state after streaming some of the video. I can see that in the android monitor. Following is the log of the thread inside from the Android Monitor : </p>
  
  <pre><code>  at java.lang.Object.wait(Native Method)   
    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.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:973)    
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1281) 
    at java.util.concurrent.Semaphore.acquire(Semaphore.java:283) 
    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:190)   
    at in.umairkhan.screencast.cast.FlashDevice$Streamer.encode(FlashDevice.java:86)  
    at in.umairkhan.screencast.cast.EncoderDevice$EncoderRunnable.run(EncoderDevice.java:55)  
    at java.lang.Thread.run(Thread.java:841)  
  </code></pre>
  
  <p>What could be the possible reason of the thread going to WAIT state ?</p>
  
  <p><strong>EDIT :</strong>
  I'm just creating the thread the normal way. Creating an object and calling the start function on that object. The object of that thread goes out of scope immediately. And there is no way I'm explicitly making the thread to go to WAIT state. I'm btw doing some intensive on that background thread. I just want to ask what could be the reason of the thread to go to WAIT state.</p>
  
  <p>I'm calling this method again and again : <a href="https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java#L174" rel="nofollow">https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java#L174</a> and passing the object of my runnable. To tell you the first if condition inside that run method is always false. I think rest of the code is somehow blocking the code.</p>