From b6251a7aa56d59e9af1926f553717d0c8e57f2a9 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 18 May 2019 02:15:52 +0700 Subject: [PATCH] Allow custom parallelism for formats --- source/net/filebot/Settings.java | 14 +++++--------- source/net/filebot/ui/rename/RenameModel.java | 6 +++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/source/net/filebot/Settings.java b/source/net/filebot/Settings.java index 6c2539b9..07b0bc30 100644 --- a/source/net/filebot/Settings.java +++ b/source/net/filebot/Settings.java @@ -22,6 +22,7 @@ import net.filebot.UserFiles.FileChooser; import net.filebot.cli.ArgumentBean; import net.filebot.util.PreferencesList; import net.filebot.util.PreferencesMap; +import net.filebot.util.SystemProperty; import net.filebot.util.PreferencesMap.JsonAdapter; import net.filebot.util.PreferencesMap.PreferencesEntry; import net.filebot.util.PreferencesMap.StringAdapter; @@ -129,16 +130,11 @@ public final class Settings { } public static int getPreferredThreadPoolSize() { - try { - String threadPool = System.getProperty("threadPool"); - if (threadPool != null) { - return Integer.parseInt(threadPool); - } - } catch (Exception e) { - debug.log(Level.WARNING, e.getMessage(), e); - } + return SystemProperty.of("threadPool", Integer::parseInt, Runtime.getRuntime().availableProcessors()).get(); + } - return Runtime.getRuntime().availableProcessors(); + public static int getPreferredParallelism() { + return SystemProperty.of("parallelism", Integer::parseInt, 1).get(); } public static LicenseModel getLicenseModel() { diff --git a/source/net/filebot/ui/rename/RenameModel.java b/source/net/filebot/ui/rename/RenameModel.java index a7f4bf6b..42c248e5 100644 --- a/source/net/filebot/ui/rename/RenameModel.java +++ b/source/net/filebot/ui/rename/RenameModel.java @@ -1,6 +1,7 @@ package net.filebot.ui.rename; import static java.util.Collections.*; +import static net.filebot.Settings.*; import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.FileUtilities.*; @@ -16,8 +17,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -162,7 +162,7 @@ public class RenameModel extends MatchModel { private final List futures = new ArrayList(); - private final Executor backgroundFormatter = new ThreadPoolExecutor(0, 1, 5L, TimeUnit.SECONDS, new LinkedBlockingQueue()); + private final Executor backgroundFormatter = Executors.newFixedThreadPool(getPreferredParallelism()); public FormattedFutureEventList(EventList source) { super(source);