7 - How does Thread Pool Executor work in Java? | Multithreading | Almighty Java

Published: 30 October 2018
on channel: Almighty Java
12,147
66

#ThreadPool #Multithreading #ThreadPoolExecutor #Executor #Java #MultithreadingInJava

For help and support - https://www.buymeacoffee.com/almighty...
========================
What is Thread Pool ?
========================
Most of the executor implementations in java.util.concurrent use thread pools, which consist of worker threads. This kind of thread exists separately from the Runnable and Callable tasks it executes and is often used to execute multiple tasks.

Using worker threads minimizes the overhead due to thread creation. Thread objects use a significant amount of memory, and in a large-scale application, allocating and deallocating many thread objects creates a significant memory management overhead.

One common type of thread pool is the fixed thread pool. This type of pool always has a specified number of threads running; if a thread is somehow terminated while it is still in use, it is automatically replaced with a new thread. Tasks are submitted to the pool via an internal queue, which holds extra tasks whenever there are more active tasks than threads.
========================
What is Thread Pool Executor ?
========================
An ExecutorService that executes each submitted task using one of possibly several pooled threads, normally configured using Executors factory methods.

Thread pools address two different problems: they usually provide improved performance when executing large numbers of asynchronous tasks, due to reduced per-task invocation overhead, and they provide a means of bounding and managing the resources, including threads, consumed when executing a collection of tasks. Each ThreadPoolExecutor also maintains some basic statistics, such as the number of completed tasks.

To be useful across a wide range of contexts, this class provides many adjustable parameters and extensibility hooks. However, programmers are urged to use the more convenient Executors factory methods Executors.newCachedThreadPool (unbounded thread pool, with automatic thread reclamation), Executors.newFixedThreadPool (fixed size thread pool) and Executors.newSingleThreadExecutor (single background thread), that pre configure settings for the most common usage scenarios.


On this page of the site you can watch the video online 7 - How does Thread Pool Executor work in Java? | Multithreading | Almighty Java with a duration of hours minute second in good quality, which was uploaded by the user Almighty Java 30 October 2018, share the link with friends and acquaintances, this video has already been watched 12,147 times on youtube and it was liked by 66 viewers. Enjoy your viewing!