HandlerThread getLooper()阻塞问题
getLooper()阻塞住了线程,这个子线程还怎么去跑run中的代码去prepare 之类等等。
getLooper()阻塞住了线程,这个子线程还怎么去跑run中的代码去prepare 之类等等。
2016-03-03
这个跟message有什么关系?looper实例都还没有,哪里来的Message?
@Override
public void run() {
mTid = Process.myTid();
Looper.prepare();
synchronized (this) {
mLooper = Looper.myLooper();
notifyAll();
}
Process.setThreadPriority(mPriority);
onLooperPrepared();
Looper.loop();
mTid = -1;
}
/**
* This method returns the Looper associated with this thread. If this thread not been started
* or for any reason is isAlive() returns false, this method will return null. If this thread
* has been started, this method will block until the looper has been initialized.
* @return The looper.
*/
public Looper getLooper() {
if (!isAlive()) {
return null;
}
// If the thread has been started, wait until the looper has been created.
synchronized (this) {
while (isAlive() && mLooper == null) {
try {
wait();
} catch (InterruptedException e) {
}
}
}
return mLooper;
}
如果在getLooper()并且run()还没有运行起来,这个时候wait()了,阻塞了,然后这个线程还怎么去返过来执行run()。我问的是这个
举报