Skip to content

Commit

Permalink
Calling the updateRegistry in executorService so that Monitor functio…
Browse files Browse the repository at this point in the history
…n is not holding the lock for long time
  • Loading branch information
Gaurav committed Dec 4, 2024
1 parent 1595fa5 commit 0595350
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ServiceFinderHub<T, R extends ServiceRegistry<T>> {
private final Lock updateLock = new ReentrantLock();
private final Condition updateCond = updateLock.newCondition();
private final AtomicBoolean updateAvailable = new AtomicBoolean(false);
private final ExecutorService executorService = Executors.newFixedThreadPool(1);
private final ExecutorService executorService = Executors.newFixedThreadPool(2);

@Getter
private final ExternalTriggeredSignal<Void> startSignal
Expand Down Expand Up @@ -134,9 +134,9 @@ public void start() {
log.info("Waiting for the service finder hub to start");
val stopwatch = Stopwatch.createStarted();
monitorFuture = executorService.submit(this::monitor);
updateAvailable();
refreshSignals.forEach(signal -> signal.registerConsumer(x -> updateAvailable()));
startSignal.trigger();
updateAvailable();
waitTillHubIsReady();
log.info("Service finder hub started in {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
Expand Down Expand Up @@ -188,7 +188,7 @@ private void monitor() {
while (!updateAvailable.get()) {
updateCond.await();
}
updateRegistry();
executorService.submit(this::updateRegistry);
}
catch (InterruptedException e) {
log.info("Updater thread interrupted");
Expand Down Expand Up @@ -245,7 +245,6 @@ private void updateRegistry() {
}

private void waitTillHubIsReady() {
log.info("executing waitTillHubIsReady");
val services = FinderUtils.getEligibleServices(serviceDataSource.services(), excludedServices);
val timeToRefresh = Math.max(hubStartTimeoutMs,
(serviceRefreshTimeoutMs * services.size()) / refresherPool.getParallelism());
Expand Down

0 comments on commit 0595350

Please sign in to comment.