获取命名队列中的任务数量? [英] Get number of tasks in a named queue?

查看:109
本文介绍了获取命名队列中的任务数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命名的任务队列。有没有办法从java API获取当前包含的任务?

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

推荐答案

有关队列的各种统计信息可在 Class QueueStatistics

Various stats about a queue are available in the Class QueueStatistics

情况下很容易遗漏注意事项(可能不属于您的情况,因为您只是想提供一个ETA,但不一定100%准确) mine):

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允许观察给定
队列上的任务正在执行的速率。 请注意,提供的统计信息仅为
的近似值,有些统计信息可能会延迟或暂时性出现
不可用

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.

您似乎正在关注的方法是 getNumTasks

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.


这篇关于获取命名队列中的任务数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆