Wait for HandlerThread to terminate after calling quit.

Calling HandlerThread.quit() or .quitSafely() doesn't immediately terminate
the thread. It just instructs the Looper not to accept any new messages and
to terminate at the next opportunity. Added a HandlerThread.join() everywhere
where the intention is to close and release all resources and to stop all
threads.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171525241
This commit is contained in:
tonihei 2017-10-09 05:51:37 -07:00 committed by Oliver Woodman
parent 54d3df4b63
commit 030f52b41b
2 changed files with 9 additions and 1 deletions

View file

@ -304,7 +304,6 @@ import java.io.IOException;
// Restore the interrupted status.
Thread.currentThread().interrupt();
}
internalPlaybackThread.quit();
}
public Looper getPlaybackLooper() {
@ -840,6 +839,7 @@ import java.io.IOException;
resetInternal(true);
loadControl.onReleased();
setState(Player.STATE_IDLE);
internalPlaybackThread.quit();
synchronized (this) {
released = true;
notifyAll();

View file

@ -212,9 +212,17 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
}
@Override
@SuppressWarnings("ThreadJoinLoop")
public void release() {
stop();
playbackThread.quitSafely();
while (playbackThread.isAlive()) {
try {
playbackThread.join();
} catch (InterruptedException e) {
// Ignore interrupt.
}
}
}
@Override