Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

ConsulCache creates new executor service for every service in ServiceHealthCache. #387

Open
pranabgarad opened this issue Jul 15, 2019 · 4 comments

Comments

@pranabgarad
Copy link

pranabgarad commented Jul 15, 2019

I have a requirement where I am listening for the list of healthy nodes for every service.

Following is the code snippet for 2 services say "service1" and "service2"

ServiceHealthCache serviceHealthCache1 = ServiceHealthCache.newCache(consul.healthClient(), "service1", true, QueryOptions.BLANK, 30);
serviceHealthCache1.addListener(serviceMap -> {
System.out.println(" serviceMap 1: " + serviceMap.keySet());
});

serviceHealthCache1.start();

ServiceHealthCache serviceHealthCache2 = ServiceHealthCache.newCache(consul.healthClient(), "service2", true, QueryOptions.BLANK, 30);
serviceHealthCache2.addListener(serviceMap -> {
System.out.println(" serviceMap 2: " + serviceMap.keySet());
});

    serviceHealthCache2.start();

ConsulCache is creating new executor service (Executors.newSingleThreadScheduledExecutor()) for every service. Since I have many services(50) that I am interested in and the number could keep on growing, wouldn't it be inefficient to keep 50 threads blocking. Is there a better way to handle this?

I am using consul client version 1.3.6

@pranabgarad
Copy link
Author

Can anyone provide some inputs?

Thanks

@alespuh
Copy link
Contributor

alespuh commented Sep 3, 2019

1.3.7 has possibility to pass your own executor service, here: #389

But it has a bug that happens when you call stop() on a cache - it will stop passed executor service which will basically stop all other caches that are using the same executor service. If you are stopping it only on app exit, then you are ok, I think.

Anyway, #396 fixes that, but is not yet released

@pranabgarad
Copy link
Author

@alespuh
Thanks for your reply. When will the fix #396 be released?

Regards,
Pranab

@alespuh
Copy link
Contributor

alespuh commented Sep 4, 2019

Who knows, it's up to the owner. I added #397 issue, so maybe it's noticed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants