Follow up to: "Fix BlockedThreadsCheck failing with un-blocked..."

The original change fixes the issue but at the expence of performance
(configuration of blocked threads check is read upon each call to
helthcheck endpint). This patch improves the performance by
memoizing the configuration only (obtaining new list of qualifiers
for each call to healthcheck endpoint).

Bug: Issue 14736
Change-Id: Ia794f17f33f198562027cb3607ad55ad0da06ffd
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsCheck.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsCheck.java
index 4e21771..78b8b01 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsCheck.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsCheck.java
@@ -17,12 +17,12 @@
 import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.BLOCKEDTHREADS;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Suppliers;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.gerrit.extensions.config.FactoryModule;
 import com.google.inject.Inject;
 import com.google.inject.Module;
 import com.google.inject.Provider;
+import com.google.inject.Singleton;
 import com.googlesource.gerrit.plugins.healthcheck.HealthCheckConfig;
 import com.googlesource.gerrit.plugins.healthcheck.HealthCheckMetrics;
 import java.lang.management.ManagementFactory;
@@ -31,9 +31,9 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
-import java.util.function.Supplier;
 import java.util.stream.Stream;
 
+@Singleton
 public class BlockedThreadsCheck extends AbstractHealthCheck {
   public static Module SUB_CHECKS =
       new FactoryModule() {
@@ -44,7 +44,7 @@
       };
 
   private final ThreadMXBean threads;
-  private final Supplier<List<Collector>> collectorsSupplier;
+  private final BlockedThreadsConfigurator collectorsSupplier;
 
   @Inject
   public BlockedThreadsCheck(
@@ -52,15 +52,15 @@
       HealthCheckConfig healthCheckConfig,
       HealthCheckMetrics.Factory healthCheckMetricsFactory,
       ThreadBeanProvider threadBeanProvider,
-      Provider<BlockedThreadsConfigurator> checksConfig) {
+      BlockedThreadsConfigurator checksConfig) {
     super(executor, healthCheckConfig, BLOCKEDTHREADS, healthCheckMetricsFactory);
     this.threads = threadBeanProvider.get();
-    this.collectorsSupplier = Suppliers.memoize(() -> checksConfig.get().collectors());
+    this.collectorsSupplier = checksConfig;
   }
 
   @Override
   protected Result doCheck() throws Exception {
-    List<Collector> collectors = collectorsSupplier.get();
+    List<Collector> collectors = collectorsSupplier.createCollectors();
     dumpAllThreads().forEach(info -> collectors.forEach(c -> c.collect(info)));
 
     // call check on all sub-checks so that metrics are populated
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsConfigurator.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsConfigurator.java
index ddc67f9..40030e1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsConfigurator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsConfigurator.java
@@ -50,7 +50,7 @@
     this.providers = getProviders(subchecks, healthCheckConfig);
   }
 
-  List<Collector> collectors() {
+  List<Collector> createCollectors() {
     return providers.stream().map(CollectorProvider::get).collect(toList());
   }