From a525c940f3e3910c052f9caffa906048bdab14fc Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 28 Jun 2014 09:21:03 -0700 Subject: Fix for threads in pool exiting --- .../daneren2005/dsub/service/DownloadService.java | 5 +++++ src/github/daneren2005/dsub/util/BackgroundTask.java | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 0c5c8e24..0a13e16e 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -29,6 +29,7 @@ import static github.daneren2005.dsub.domain.PlayerState.PREPARING; import static github.daneren2005.dsub.domain.PlayerState.STARTED; import static github.daneren2005.dsub.domain.PlayerState.STOPPED; +import github.daneren2005.dsub.R; import github.daneren2005.dsub.audiofx.AudioEffectsController; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.audiofx.VisualizerController; @@ -45,6 +46,7 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.MediaRouteManager; import github.daneren2005.dsub.util.ShufflePlayBuffer; import github.daneren2005.dsub.util.SimpleServiceBinder; +import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.util.compat.RemoteControlClientHelper; import github.daneren2005.serverproxy.BufferProxy; @@ -263,9 +265,11 @@ public class DownloadService extends Service { if(bufferTask != null) { bufferTask.cancel(); + bufferTask = null; } if(nextPlayingTask != null) { nextPlayingTask.cancel(); + nextPlayingTask = null; } if(remoteController != null) { remoteController.stop(); @@ -975,6 +979,7 @@ public class DownloadService extends Service { public synchronized void reset() { if (bufferTask != null) { bufferTask.cancel(); + bufferTask = null; } try { // Only set to idle if it's not being killed to start RemoteController diff --git a/src/github/daneren2005/dsub/util/BackgroundTask.java b/src/github/daneren2005/dsub/util/BackgroundTask.java index 63515f19..ad9d89c0 100644 --- a/src/github/daneren2005/dsub/util/BackgroundTask.java +++ b/src/github/daneren2005/dsub/util/BackgroundTask.java @@ -135,13 +135,20 @@ public abstract class BackgroundTask implements ProgressListener { } public void cancel() { - cancelled = true; - if(task != null) { - task.cancel(); + if(cancelled) { + // Already cancelled, don't do anything + return; } - if(cancelListener != null) { - cancelListener.onCancel(); + cancelled = true; + if(task != null && task.isRunning()) { + if(cancelListener != null) { + cancelListener.onCancel(); + } else { + task.cancel(); + } + + task = null; } } public boolean isCancelled() { -- cgit v1.2.3