且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

队列线程黑莓

更新时间:2023-11-25 13:06:22

如果你只是想在一个单线程串行执行一串任务和顺序并不重要,你可以创建一个的Timer 对象(它有其自己的线程),那么每个任务添加到它作为一个TimerTask 。如果您使用的0或1的延迟安排,它会基本上是尽快运行任务。而且,由于一个定时器只有一个线程,如果您安排多个任务的同时,将确保只有一个会同时运行。

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.

顺便说一句,我是在黑莓开发者大会上,今年说给RIM的工程师,他说,作为OS 5.0中不再有限制了线程的数量 - 所以,这正成为越来越少的关注。

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.