Shutdown ExecutorService in ExternalPluginManager

Also name threads for easy identification
This commit is contained in:
swazrgb
2020-05-24 03:29:30 +02:00
parent 34c40a6d7d
commit 3ce0cb9dc1

View File

@@ -24,6 +24,7 @@
*/ */
package net.runelite.client.plugins; package net.runelite.client.plugins;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.CreationException; import com.google.inject.CreationException;
import com.google.inject.Injector; import com.google.inject.Injector;
@@ -685,8 +686,13 @@ public class ExternalPluginManager
List<Plugin> scannedPlugins = new CopyOnWriteArrayList<>(); List<Plugin> scannedPlugins = new CopyOnWriteArrayList<>();
// some plugins get stuck on IO, so add some extra threads // some plugins get stuck on IO, so add some extra threads
ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2,
new ThreadFactoryBuilder()
.setNameFormat("plugin-manager-%d")
.build());
try
{
for (Plugin plugin : plugins) for (Plugin plugin : plugins)
{ {
Class<? extends Plugin> clazz = plugin.getClass(); Class<? extends Plugin> clazz = plugin.getClass();
@@ -750,7 +756,16 @@ public class ExternalPluginManager
} }
}); });
} }
}
finally
{
List<Runnable> unfinishedTasks = exec.shutdownNow();
if (!unfinishedTasks.isEmpty())
{
// This shouldn't happen since we Future#get all tasks submitted to the executor
log.warn("Did not complete all update tasks: {}", unfinishedTasks);
}
}
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")