Bug 1300543 - IconRequestExecutor: Add custom thread pool executor and thread factory. r=ahunt
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 05 Sep 2016 15:24:07 +0200
changeset 312974 dd2d29dbd7c5ac4af4540ca679658c0b1568ee7f
parent 312973 243fe9c65a048abe71545e206a8a7d05088dd1af
child 312975 2269f770b2e7a2d103077ca1ada9af1785b648b2
push id81509
push usercbook@mozilla.com
push dateWed, 07 Sep 2016 15:23:10 +0000
treeherdermozilla-inbound@80dccdd8c94a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1300543
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1300543 - IconRequestExecutor: Add custom thread pool executor and thread factory. r=ahunt The custom executor behaves like the one returned by Executors.newSingleThreadExecutor(). However the created thread will have a unique name ("GeckoIconTask") and this will make tracing the thread much easier. MozReview-Commit-ID: 7y0EMGmNLkG
mobile/android/base/java/org/mozilla/gecko/icons/IconRequestExecutor.java
--- a/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestExecutor.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/IconRequestExecutor.java
@@ -1,43 +1,47 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.icons;
 
+import android.support.annotation.NonNull;
+
 import org.mozilla.gecko.icons.loader.ContentProviderLoader;
 import org.mozilla.gecko.icons.loader.DataUriLoader;
+import org.mozilla.gecko.icons.loader.DiskLoader;
 import org.mozilla.gecko.icons.loader.IconDownloader;
 import org.mozilla.gecko.icons.loader.IconGenerator;
+import org.mozilla.gecko.icons.loader.IconLoader;
 import org.mozilla.gecko.icons.loader.JarLoader;
 import org.mozilla.gecko.icons.loader.LegacyLoader;
-import org.mozilla.gecko.icons.loader.IconLoader;
 import org.mozilla.gecko.icons.loader.MemoryLoader;
-import org.mozilla.gecko.icons.loader.DiskLoader;
 import org.mozilla.gecko.icons.preparation.AboutPagesPreparer;
 import org.mozilla.gecko.icons.preparation.AddDefaultIconUrl;
 import org.mozilla.gecko.icons.preparation.FilterKnownFailureUrls;
 import org.mozilla.gecko.icons.preparation.FilterMimeTypes;
 import org.mozilla.gecko.icons.preparation.FilterPrivilegedUrls;
 import org.mozilla.gecko.icons.preparation.LookupIconUrl;
 import org.mozilla.gecko.icons.preparation.Preparer;
 import org.mozilla.gecko.icons.processing.ColorProcessor;
+import org.mozilla.gecko.icons.processing.DiskProcessor;
 import org.mozilla.gecko.icons.processing.MemoryProcessor;
 import org.mozilla.gecko.icons.processing.Processor;
 import org.mozilla.gecko.icons.processing.ResizingProcessor;
-import org.mozilla.gecko.icons.processing.DiskProcessor;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Executor for icon requests.
  */
 /* package-private */ class IconRequestExecutor {
     /**
      * Loader implementation that generates an icon if none could be loaded.
      */
@@ -110,17 +114,37 @@ import java.util.concurrent.Future;
 
             // Resize the icon to match the target size (if possible)
             new ResizingProcessor(),
 
             // Store the icon in the memory cache
             new MemoryProcessor()
     );
 
-    private static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
+    private static final ExecutorService EXECUTOR;
+    static {
+        final ThreadFactory factory = new ThreadFactory() {
+            @Override
+            public Thread newThread(@NonNull Runnable runnable) {
+                Thread thread = new Thread(runnable, "GeckoIconTask");
+                thread.setDaemon(false);
+                thread.setPriority(Thread.NORM_PRIORITY);
+                return thread;
+            }
+        };
+
+        // Single thread executor
+        EXECUTOR = new ThreadPoolExecutor(
+                1, /* corePoolSize */
+                1, /* maximumPoolSize */
+                0L, /* keepAliveTime */
+                TimeUnit.MILLISECONDS,
+                new LinkedBlockingQueue<Runnable>(),
+                factory);
+    }
 
     /**
      * Submit the request for execution.
      */
     /* package-private */ static Future<IconResponse> submit(IconRequest request) {
         return EXECUTOR.submit(
                 new IconTask(request, PREPARERS, LOADERS, PROCESSORS, GENERATOR)
         );