如何暂停一个线程的消息队列中的Andr​​oid? [英] How to pause a Thread's Message Queue in Android?

查看:222
本文介绍了如何暂停一个线程的消息队列中的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过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.

这篇关于如何暂停一个线程的消息队列中的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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