黑莓中的队列线程
我查看了 BB API(5.0),但找不到任何串行执行一批线程的方法。我知道 BB 对启动的线程数量有限制,所以如果用户点击速度足够快但我找不到像线程池这样的东西,我不想启动 7。
是否有一个简单的解决方案,或者我是否必须创建一个数据结构?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想在单个线程上串行执行一堆任务并且顺序并不重要,您可以创建一个 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.
我已经在 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).