Search code examples
concurrencythreadpoolguavahystrix

What is the impact of libraries that maintain their own threads pool?


I'm using Google Guava and Netflix Hystrix libraries in our project. Each library comes with it is own pool of threads that you can configure.

Thats made think of the impact of that. I mean each library is maintaining its own pool of threads and of course, each hardware has its own optimal setup.

Lets say that I setup Guava for 50 in its thread pool and Hystrix for 40 in its thread pool. What is going to happen? They will compete over resources?


Solution

  • I'm not familiar with Hystrix, but your example for Guava is:

    ListeningExecutorService service =
        MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
    

    In this case, Guava isn't providing a thread pool at all... you're configuring a thread pool in your code using the standard JDK methods for creating a thread pool, then wrapping that ExecutorService using a Guava method.

    To (hopefully) answer your question, if you have two separate thread pools, they are in fact separate... they won't share any threads. If one has 50 threads and one has 40, you'll have 90 total threads. Again, I don't know how whatever you're doing with Hystrix works, but if it's similar to what you're doing with Guava (creating a thread pool using Executors.newFixedThreadPool(n) and passing it to something else), it's possible to just create one thread pool and have both libraries use it, in which case they will share threads.