Android 处理程序唤醒线程
我有一个单独的线程,它是一个声明处理程序的循环线程,如下所示:
class LooperThread extends Thread{
Handler h = null;
@Override
public void run(){
Looper.prepare();
h = new MyHandler();
Looper.loop();
}
}
我还有一个正在休眠的单独线程。 myHandler 的代码在我的其他线程正在等待的同一个锁上进行同步,然后在完成一些工作后调用 Notify。但是,原始线程正在等待,并且处理程序无法到达从单独服务发送到处理程序的消息。我确信该消息是从该服务发送的。我知道处理程序为其构建的线程创建一个消息队列,但是,如果处理程序构建在单独的循环线程上,如果原始线程处于休眠状态,那么该线程不会休眠吗?我尝试过 handlerThread 和其他一些替代方案,但没有成功。任何帮助将不胜感激。谢谢。
I have a a separate thread that is a looping thread that declares a handler, as shown below:
class LooperThread extends Thread{
Handler h = null;
@Override
public void run(){
Looper.prepare();
h = new MyHandler();
Looper.loop();
}
}
And I also have a seperate thread that is sleeping. The code for myHandler synchronizes on the same lock that my other thread is waiting on and then calls Notify after doing some work. However, the original thread waits and the message that is sent from the separate service to the handler is not being reached by the handler. I am certain that the message is being sent from the service. I understand that a Handler creates a message queue for the thread it was built on however, if the handler is built on a separate looping thread wouldn't this thread not sleep if the original thread is? I have tried handlerThread and a few other alternatives but to no avail. Any help would be greatly appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论