如何暂停一个线程的消息队列中的Andr​​oid?队列、线程、消息、oid

2023-09-08 08:38:49 作者:鸡蛋它妈,快到碗里来

我通过Handler.post排队了一堆可运行的成线()。我想一张纸条发送到该线程,它应该暂停的能力。

I am queuing up a bunch of runnables into a thread via a Handler.post(). I would like the ability to send a note to that thread that it should pause.

通过暂停我的意思是,完成可运行或消息您当前的工作,但不要去在消息队列中下一条消息或可运行的,直到我告诉你继续。

By pause I mean, finish the runnable or message you are currently working on, but don't go to the next message or runnable in your message queue until I tell you to continue.

推荐答案

在情况下,任何人都找到自己的方式对这个问题,我结束了一个ThreadPoolExecutor的准备,使用例如code在它的创建PausableThreadPoolExecutor文档:的http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html

In case anyone else finds their way to this question, I ended up going with a ThreadPoolExecutor, using the example code in it's documentation for creating a PausableThreadPoolExecutor: http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html

它不使用消息队列或弯针,但它实现了什么,我要怎样做,这是创造的Runnable的队列能够被暂停和/或取消。它的优点是能够为s $ P $垫队列在线程指定数量的额外的奖励。

It doesn't use the Message Queue or Looper but it accomplishes what I was trying to do, which was to create a queue of Runnables that was able to be paused and/or canceled. It has the added bonus of being able to spread the queue over a specified number of threads.