From 1b58ca11311ad872624a3f84019fbc4e116e241d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 25 Aug 2013 13:50:30 -0700 Subject: Remove race condition for access to eventHandler --- .../service/DownloadServiceLifecycleSupport.java | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index e0019559..4e3ec29c 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -117,6 +117,16 @@ public class DownloadServiceLifecycleSupport { Looper.prepare(); eventLooper = Looper.myLooper(); eventHandler = new Handler(eventLooper); + + // Deserialize queue before starting looper + try { + lock.lock(); + deserializeDownloadQueueNow(); + setup.set(true); + } finally { + lock.unlock(); + } + Looper.loop(); } }).start(); @@ -176,8 +186,6 @@ public class DownloadServiceLifecycleSupport { commandFilter.addAction(DownloadServiceImpl.CMD_NEXT); downloadService.registerReceiver(intentReceiver, commandFilter); - deserializeDownloadQueue(); - new CacheCleaner(downloadService, downloadService).clean(); } @@ -248,20 +256,6 @@ public class DownloadServiceLifecycleSupport { FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER); } - private void deserializeDownloadQueue() { - eventHandler.post(new Runnable() { - @Override - public void run() { - try { - lock.lock(); - deserializeDownloadQueueNow(); - setup.set(true); - } finally { - lock.unlock(); - } - } - }); - } private void deserializeDownloadQueueNow() { State state = FileUtil.deserialize(downloadService, FILENAME_DOWNLOADS_SER); if (state == null) { -- cgit v1.2.3