Merge pull request #2612 from swazrgb/shutdown-executor

client: Also shutdown executor in PluginManager
This commit is contained in:
Owain van Brakel
2020-05-24 19:35:58 +02:00
committed by GitHub
2 changed files with 47 additions and 32 deletions

View File

@@ -688,7 +688,7 @@ public class ExternalPluginManager
// 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() new ThreadFactoryBuilder()
.setNameFormat("plugin-manager-%d") .setNameFormat("external-plugin-manager-%d")
.build()); .build());
try try

View File

@@ -34,6 +34,7 @@ import com.google.common.graph.Graphs;
import com.google.common.graph.MutableGraph; import com.google.common.graph.MutableGraph;
import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath;
import com.google.common.reflect.ClassPath.ClassInfo; import com.google.common.reflect.ClassPath.ClassInfo;
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;
@@ -401,8 +402,13 @@ public class PluginManager
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
// 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
{
List<Plugin> scannedPlugins = new CopyOnWriteArrayList<>(); List<Plugin> scannedPlugins = new CopyOnWriteArrayList<>();
sortedPlugins.forEach(group -> sortedPlugins.forEach(group ->
{ {
@@ -440,9 +446,18 @@ public class PluginManager
}); });
log.info("Plugin instantiation took {}ms", System.currentTimeMillis() - start); log.info("Plugin instantiation took {}ms", System.currentTimeMillis() - start);
return scannedPlugins; return scannedPlugins;
} }
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);
}
}
}
public boolean startPlugin(Plugin plugin) throws PluginInstantiationException public boolean startPlugin(Plugin plugin) throws PluginInstantiationException
{ {