user3203425 user3203425 - 1 year ago 64
Java Question

Get number of tasks in a named queue?

I have a named task queue. Is there a way to get the # of tasks it currently contains, from the java API?

I know I can check the console page for it, but I'd like to get the count via code so I can report back to the user how many tasks are in there so they know how long they'll have to wait roughly before their task is going to get serviced.


Answer Source

Various stats about a queue are available in the Class QueueStatistics

Easy to miss note important in some cases (probably not in yours, as you just want to provide an ETA, which doesn't have to be 100% precise) (emphasis mine):

QueueStatistics allow observation of the rate that tasks on a given queue are being executed. Note that statistics provided are only approximate, and some statistics may be delayed or transiently unavailable.

The method that seems to be what you're looking after is getNumTasks:


public int getNumTasks()

    The approximate number of non-completed tasks in the queue.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download