Get number of tasks in a named queue?

2019-07-24 11:07发布

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.

Thanks

1条回答
beautiful°
2楼-- · 2019-07-24 11:52

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:

getNumTasks

public int getNumTasks()

Returns:
    The approximate number of non-completed tasks in the queue.
查看更多
登录 后发表回答