How to use DispatchQueue.isExecuting

23 views
Skip to first unread message

jet...@web.de

unread,
Jul 2, 2013, 3:05:41 AM7/2/13
to hawtdi...@googlegroups.com
Hello,

I have a DispatchQueue on which I invoked execute several times. All the runnables that were passed on to the execute method sleep for a long time. This way the current executed runnable while sleeping prevents the runnables in the queue from running. So I thought that this would result in DispatchQueue.isExecuting() returning true when there are still runnables waiting in the queue, but it returns false. What I basically am looking for is a way to figure out whether the queue is idle or not.

Thanks for any hints,
Oliver

Hiram Chirino

unread,
Jul 2, 2013, 8:00:39 AM7/2/13
to hawtdispatch
isExecuting returns true if it's executing on the current thread. The
only way you can do that is by enabling queue profiling using:

dispatchQueue.profile(true);

and then looking at the metrics of the queue like:

size = dispatchQueue.metrics().enqueued - dispatchQueue.metrics().dequeued;
> --
> You received this message because you are subscribed to the Google Groups
> "hawtdispatch" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hawtdispatch...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Hiram Chirino

Engineering | Red Hat, Inc.

hchi...@redhat.com | fusesource.com | redhat.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo
Reply all
Reply to author
Forward
0 new messages