PriorityQueue Workers

May 9, 2011 at 8:07 PM


I noticed that when adding a work item to the PriorityQueue, it is not executed on the workWorker WorkerThread. The WorkerThread executes the workitem using the thread pool, so work items don't wait for each other. Is this by design? If so, i'd like a way to just use a single thread for executing work items. (I fixed it for my application by not queueing on the thead pool but directly calling the item().).

Thanks for the framework by the way :)






May 11, 2011 at 5:58 PM

Hi -

Yes, it ends up going to the thread pool.  It's not the original design, but it's by design.  My original plan was to have all of this be serialized to keep work throttled and avoid starving the UI thread.  It's been a while but I think that if I had it just directly call the work item, it turned into deadlock city because a lot of the downstream work would end up being put back on to the same queue, and the worker thread couldn't pump.  

So this thing isn't as magical as I'd hoped it to be, but the sleep in there does ensure that the worker thread has to yield a fair amount of time to the UI thread which lets things drain out of the queue and get processed.  The overall goal is to let operations take a little longer in absolute clock time, but have a responsive UI at all times.