[Android] Prevent RejectedExecutionException

Geoffrey Métais git at videolan.org
Mon Sep 4 18:22:54 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Sep  4 18:21:59 2017 +0200| [417c3ad081ee70f687569c4d1fd8123ec63a455b] | committer: Geoffrey Métais

Prevent RejectedExecutionException

> https://code.videolan.org/videolan/vlc-android/commit/417c3ad081ee70f687569c4d1fd8123ec63a455b
---

 .../org/videolan/vlc/gui/BaseQueuedAdapter.java    | 33 ++++++++++++----------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
index 97b74de0e..6585035d6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
@@ -32,6 +32,7 @@ import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
 
 public abstract class BaseQueuedAdapter <T extends MediaLibraryItem, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
     protected final ExecutorService mUpdateExecutor = Executors.newSingleThreadExecutor();
@@ -65,21 +66,23 @@ public abstract class BaseQueuedAdapter <T extends MediaLibraryItem, VH extends
 
     @MainThread
     private void internalUpdate(final ArrayList<T> newList) {
-        mUpdateExecutor.execute(new Runnable() {
-            @Override
-            public void run() {
-                final ArrayList<T> finalList = prepareList(newList);
-                final DiffUtil.DiffResult result = DiffUtil.calculateDiff(createCB(finalList), detectMoves());
-                VLCApplication.runOnMainThread(new Runnable() {
-                    @Override
-                    public void run() {
-                        mDataset = finalList;
-                        result.dispatchUpdatesTo(BaseQueuedAdapter.this);
-                        processQueue();
-                    }
-                });
-            }
-        });
+        try {
+            mUpdateExecutor.execute(new Runnable() {
+                @Override
+                public void run() {
+                    final ArrayList<T> finalList = prepareList(newList);
+                    final DiffUtil.DiffResult result = DiffUtil.calculateDiff(createCB(finalList), detectMoves());
+                    VLCApplication.runOnMainThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            mDataset = finalList;
+                            result.dispatchUpdatesTo(BaseQueuedAdapter.this);
+                            processQueue();
+                        }
+                    });
+                }
+            });
+        } catch (RejectedExecutionException ignored) {} // Will be retried
 
     }
 



More information about the Android mailing list