I'm going thru HandlerThread source code and I can't understand why part of HandlerThread's run() method is synchronized?
@Override
public void run() {
mTid = Process.myTid();
Looper.prepare();
synchronized (this) {
mLooper = Looper.myLooper();
notifyAll();
}
Process.setThreadPriority(mPriority);
onLooperPrepared();
Looper.loop();
mTid = -1;
}
I thought that the run()
method is called on the thread it belongs to so how can it be reached from multiple threads?
I expect it has sth to do with the situation when somebody create and start multiple instances of the same HandlerThread class.