0

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 :

  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)  

What could be the possible reason of the thread going to WAIT state ?

EDIT : 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.

I'm calling this method again and again : https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java#L174 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.

omerjerk
  • 4,090
  • 5
  • 40
  • 57
  • sorry, what's the android monitor? – Blackbelt May 13 '14 at 13:31
  • It shows the insights of your android device like what are the threads running, your app's heap size and yes the logcat and a lot of other things that I don't know. – omerjerk May 13 '14 at 13:33
  • is com.koushikdutta.async.AsyncServer.run a class that you wrote? – Blackbelt May 13 '14 at 13:34
  • 1
    Post some code where the Thread and stream reading is included. – Steve Benett May 13 '14 at 13:36
  • I'm using an open source library to create a Server on my android device. This is the AsyncServer class :https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java – omerjerk May 13 '14 at 13:36
  • It looks to me like you might be using the AsyncServer class in the wrong way. Please post some code. – marcone May 13 '14 at 16:35
  • I've updated the question. Just due to some reasons I can't post the code. – omerjerk May 13 '14 at 19:27
  • Hi! I also using AndroidAsync and also bumped into this bug! Could you share your solution or just give a tip, please? – Slava Apr 27 '16 at 13:18
  • Please, take a look on Andrepew answer: https://github.com/koush/AndroidAsync/issues/310 It seems like it works, but I still need to test it. – Slava Apr 27 '16 at 14:06

2 Answers2

0

If you can get hold of the thread object, try using thread.setPriority() in order to set a lower priority. That way you will find out if it is going into WAIT mode due to another thread blocking it

Shane
  • 150
  • 6
0

According to the stack trace, com.koushikdutta.async.AsyncServer.run is calling java.util.concurrent.Semaphore.acquire, and it's blocking on the semaphore. The thread is waiting for the semaphore to be released by another thread.

The Dalvik WAIT thread state is, literally, a thread that has called Object.wait(). For the full thread state reference, see this post.

Community
  • 1
  • 1
fadden
  • 51,356
  • 5
  • 116
  • 166