黑莓中的队列线程

发布于 2024-10-03 18:07:29 字数 137 浏览 3 评论 0 原文

我查看了 BB​​ API(5.0),但找不到任何串行执行一批线程的方法。我知道 BB 对启动的线程数量有限制,所以如果用户点击速度足够快但我找不到像线程池这样的东西,我不想启动 7。

是否有一个简单的解决方案,或者我是否必须创建一个数据结构?

I've looked at the BB API(5.0) and I can't find any way of serially executing a batch of threads. I know BB has a limit on the number of threads it will launch, so I don't want to launch 7 if the user clicks through things fast enough but I cannot find anything like a thread pool.

Is there an easy fix for this or do I have to create a data structure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多孤肩上扛 2024-10-10 18:07:29

如果您只想在单个线程上串行执行一堆任务并且顺序并不重要,您可以创建一个 Timer 对象(有自己的线程),然后将每个任务作为 TimerTask。如果您以 0 或 1 的延迟来安排它,它实际上会尽快运行该任务。而且由于 Timer 只有一个线程,如果您同时调度多个任务,它将确保一次只有一个任务运行。

顺便说一句,我在今年的 BlackBerry 开发者大会上与一位 RIM 工程师交谈,他说从 OS 5.0 开始,线程数量不再受到限制,因此这已变得越来越不令人担忧。

If you just want to execute a bunch of tasks on a single thread serially and order isn't important, you could create a Timer object (which has its own thread) then add each task to it as a TimerTask. If you schedule it with a delay of 0 or 1, it will essentially run that task as soon as possible. And since a Timer only has a single thread, if you schedule multiple tasks concurrently, it will ensure that only one will run at a time.

Incidentally, I was talking to a RIM engineer at the BlackBerry Developer Conference this year and he said that as of OS 5.0 there are no longer limits to the number of threads -- so this is becoming less and less of a concern.

夏尔 2024-10-10 18:07:29

我已经在 4.5 上测试了 Jeff Heaton 的线程池示例,它可以工作。 (http://www.informit.com/articles/article. aspx?p=30483&seqNum=1)。

I've tested Jeff Heaton's Thread Pool example on 4.5 and it works. (http://www.informit.com/articles/article.aspx?p=30483&seqNum=1).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文