Java - How to use ExecutorService | Executor Framework - Part 1

  Рет қаралды 3,460

Alternative Degree

Alternative Degree

Күн бұрын

This video talks about the basics of ExecutorService. It explains the importance of thread pools in java. Executor framework provides components to manage worker threads.
You can create a thread pool by calling one of the factory methods in Executors class
newFixedThreadPool - Fixed number of threads
newCachedThreadPool - Thread pool size is not limited
newSingleThreadExecutor - A Single thread in the pool
newScheduledThreadPool - Run tasks at regular intervals
In this video we talk in detail about newFixedThreadPool executor.
As the name suggests the thread pool size is fixed.
The corePoolSize and the maximumPoolSize is the same
The number of threads that can be created is dictated by the maximum pool size.
It is backed by a LinkedBlockingQueue - unbounded in size & tasks are executed in FIFO order
If all the worker threads are busy processing tasks, then any new tasks that come in are placed in a queue. Once a worker thread is free, it grabs the tasks from the queue
If a thread dies before shutdown because of some exception, then a new thread takes it place and starts serving new tasks.
Fixed thread pool is a good choice when you want to limit the number of concurrent task
Executor Lifecycle:
ExecutorService can be in three states
Running
Shutting Down
Terminated
Some of the important Lifecycle management methods of ExecutorService
shutdown() - allows graceful shutdown
shutdownNow() - abrupt shutdown
isShutdown()
isTerminated()
awaitTermination(long timeout, TimeUnit unit)
For introduction to multithreading in Java, please look into my previous videos
• Java Multithreading | ...
• Java Multithreading | ...
#Java #Multithreading #ExecutorService #newFixedThreadPool

Пікірлер: 1
@gregchen4023
@gregchen4023 3 жыл бұрын
I do not agree with you regarding the garbage collection. Idle threads do not result in garbage collection.
Java - Executor Service | Executor Framework - Part 2
13:25
Alternative Degree
Рет қаралды 341
Life hack 😂 Watermelon magic box! #shorts by Leisi Crazy
00:17
Leisi Crazy
Рет қаралды 73 МЛН
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 6 МЛН
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 3,8 МЛН
The Problem With Microservices
17:47
Continuous Delivery
Рет қаралды 434 М.
Cryptography 101 for Java developers by Michel Schudel
42:59
Java ExecutorService - Part 1 - Introduction
10:12
Defog Tech
Рет қаралды 417 М.
Why Vertical LLM Agents Are The New $1 Billion SaaS Opportunities
37:06
Spring Boot - Tomcat Worker Threads : Load Shedding
32:04
Alternative Degree
Рет қаралды 1,5 М.
9. Java Memory Management and Garbage Collection in Depth
48:48
Concept && Coding - by Shrayansh
Рет қаралды 82 М.
Life hack 😂 Watermelon magic box! #shorts by Leisi Crazy
00:17
Leisi Crazy
Рет қаралды 73 МЛН