Commit 05acaeaa authored by Ludovic Fauvet's avatar Ludovic Fauvet

ThumbnailerManager: interrupt the thread when calling stop()

This fixes the issue where the ThumbnailerManager was generating only a
single thumbnail before stopping unexpectedly. Without a explicit call
to stop().
The reason of the issue was that the thread was sleeping (waiting for
new jobs) and stopped while being in that state. Later, when a new job
was added the thread woke up and stopped after the first thumbnail as
requested previously.
parent 6f7a8ce6
......@@ -70,10 +70,10 @@ public class ThumbnailerManager implements Runnable {
}
public void start(VideoListFragment videoListFragment) {
isStopping = false;
if (mThread == null || mThread.getState() == State.TERMINATED) {
mVideoListFragment = videoListFragment;
mVideoListFragment.setThumbnailerManager(this);
isStopping = false;
mThread = new Thread(this);
mThread.start();
}
......@@ -81,6 +81,7 @@ public class ThumbnailerManager implements Runnable {
public void stop() {
isStopping = true;
mThread.interrupt();
}
/**
......@@ -121,7 +122,7 @@ public class ThumbnailerManager implements Runnable {
while (!isStopping) {
lock.lock();
// Get the id of the file browser item to create its thumbnail.
boolean killed = false;
boolean interrupted = false;
while (mItems.size() == 0) {
try {
MainActivity.hideProgressBar(mContext);
......@@ -129,11 +130,12 @@ public class ThumbnailerManager implements Runnable {
totalCount = 0;
notEmpty.await();
} catch (InterruptedException e) {
killed = true;
interrupted = true;
Log.i(TAG, "interruption probably requested by stop()");
break;
}
}
if (killed) {
if (interrupted) {
lock.unlock();
break;
}
......@@ -172,8 +174,11 @@ public class ThumbnailerManager implements Runnable {
try {
mVideoListFragment.await();
} catch (InterruptedException e) {
Log.i(TAG, "interruption probably requested by stop()");
break;
} catch (BrokenBarrierException e) {
Log.e(TAG, "Unexpected BrokenBarrierException");
e.printStackTrace();
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment