About threads and ThreadPoolExecutor in Java

In what situations should we use threads

What if we simply spawn new threads and why we should use thread pools

About Executors.newFixedThreadPool() and why you should not use it in a production environment

Executors.newFixedThreadPool(int nThreads)
Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most nThreads threads will be active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available. If any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks. The threads in the pool will exist until it is explicitly shutdown.

How should we use the thread pool implementation, ThreadPoolExecutor, provided by Java API in a production ready way

Leave a comment