multithreading
ExecutorService and Thread Pool types.
Why use it?
Decouples task submission from task execution. Manages a pool of threads instead of creating a new one for every task.
Types:
- FixedThreadPool: Fixed number of threads.
- CachedThreadPool: Creates new threads as needed, reuses idle ones.
- SingleThreadExecutor: Exactly one thread.
- ScheduledThreadPool: For delayed or periodic tasks.
Crucial Note:
Avoid using Executors.newCachedThreadPool() for high-load systems because it can create an unbounded number of threads, leading to OOM.