From e93e67ba88c901cfd3050256e474af07000b0918 Mon Sep 17 00:00:00 2001 From: daneren2005 Date: Fri, 10 May 2013 16:21:59 -0600 Subject: Don't bother allowing multiple serialize tasks to wait --- .../dsub/service/DownloadServiceLifecycleSupport.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index e1df05a8..a31ac657 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; import android.content.BroadcastReceiver; import android.content.Context; @@ -56,6 +57,7 @@ public class DownloadServiceLifecycleSupport { private BroadcastReceiver ejectEventReceiver; private PhoneStateListener phoneStateListener; private boolean externalStorageAvailable= true; + private ReentrantLock lock = new ReentrantLock(); /** * This receiver manages the intent that could come from other applications. @@ -310,8 +312,9 @@ public class DownloadServiceLifecycleSupport { private class SerializeTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { - synchronized(DownloadServiceLifecycleSupport.this) { + if(lock.tryLock()) { serializeDownloadQueueNow(); + lock.unlock(); } return null; } @@ -319,9 +322,9 @@ public class DownloadServiceLifecycleSupport { private class DeserializeTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { - synchronized(DownloadServiceLifecycleSupport.this) { - deserializeDownloadQueueNow(); - } + lock.lock(); + deserializeDownloadQueueNow(); + lock.unlock(); return null; } } -- cgit v1.2.3