Java ExecutorService - Part 3 - Constructor & LifeCycle methods

preview_player
Показать описание
Learn how to parallelize your tasks and operations easily in Java without cooking up your own Threads.

Channel
----------------------------------
Master difficult programming concepts in few minutes. I try to explain difficult concepts like Java concurrency in simple to understand manner using animations and small code snippets. Explore videos on topics like Spring Boot, Cloud Foundry, Java 8 (with more coming soon). I am happy to clarify your doubts. Ask me anything in the comments. I am also happy to take requests for new videos.

New video added every Sunday.

Playlists
----------------------------------

Popular Videos
----------------------------------
Рекомендации по теме
Комментарии
Автор

ultimate!!! Now let the interviewer ask something about executorservice. GAME ON!!

pratikmishra
Автор

I have enrolled for course on Udemy for multi threading but this is far better than that... Hats off for detailed information. Keep posting thanks

RohitPal-lzwf
Автор

Introduction:
- The video explores advanced topics related to the `ExecutorService` in Java.
- It covers parameters for creating thread pools, types of queues, rejection handling, and lifecycle methods.

Advanced Topics Covered:
1. Parameters for Creating Thread Pools:
- Core pool size: Initial size for the thread pool.
- Max pool size: Upper threshold for the thread pool size.
- Keepalive time: Time for which idle threads remain alive before being killed.
- Work queue: Type of queue used to store tasks.
- Thread factory: Factory for creating new threads.
- Rejection handler: Policy for handling rejected tasks.

2. Types of Queues:
- Linked blocking queue: Unbounded queue for fixed and single-threaded executors.
- Synchronous queue: Queue with a single storage slot for cached thread pool.
- Delayed work queue: Queue for scheduling tasks based on scheduled time.

3. Rejection Handling Policies:
- Abort policy: Throws a runtime exception for rejected tasks.
- Discard policy: Silently discards rejected tasks.
- Discard oldest policy: Discards the oldest task in the queue for rejected tasks.
- Caller runs policy: Asks the caller to execute the rejected task.

4. Lifecycle Methods:
- `shutdown()`: Initiates shutdown but does not immediately shut down the executor service.
- `isShutdown()`: Checks if shutdown has been initiated.
- `isTerminated()`: Checks if shutdown is completed.
- `awaitTermination()`: Blocks until all tasks are completed or a timeout occurs.
- `shutdownNow()`: Initiates shutdown and returns tasks that were not executed.

Summary:
- Understanding parameters for creating thread pools helps customize the behavior of the `ExecutorService`.
- Different types of queues are used based on the nature of the thread pool and task scheduling requirements.
- Rejection handling policies dictate how rejected tasks are managed.
- Lifecycle methods help control the shutdown process of the executor service.

jaleelpasha
Автор

Your playlist on java concurrency is by far the best out there on youtube

arambh-gaur
Автор

Thanks a lot. Multi-threading concepts are more clear after watching your videos.

RahulSingh-qesw
Автор

Want more playlists like this Sir, you made our life easy

narendragadhela
Автор

Thanks Youtube for recommending this amazing channel

viveksinghdroid
Автор

0:30 instantiating the fixed thread pool with newFixedThreadPool calls the ThreadPoolExecutor constructor behind the scenes

Core pool size initial number of threads in pool
Current pool size can be bigger if new threads created

Max pool size

Keep alive time if thread not active gets killed and pool decreases
Core threads are not killed when idle except if allowCoreThreadTimeOut is true

3:00 pool params for different executors

5:00 queue types for different executors

LinkedBlockingQueue can keep increasing, used for fixed and single threaded executors, because the threads are bounded, so the task storage area need to be unbounded so we can keep submitting tasks asynchronously

SynchronousQueue is a queue with a single slot, used in CachedThreadPool because threads are unbounded so storage space for tasks can be bounded, new threads will be created to take the tasks being submitted

DelayedWorkQueue for scheduledThreadPool

ArrayBlockingQueue fixed size, if queue is full new thread is created up to maxPoolSize

Continue notes

mostinho
Автор

Great videos as always, thank you so much for all the learning content here

akshatmehra
Автор

The comparative analysis diagram in 4:15 is awesome...!!

kingshukjana
Автор

Really got clarity helped me in interviews, lots of confusion in understanding thread pool u cleared every thing, one more request from my side we want vedios on nio streams, reactive programming sir pls help us by providing u r vedios u r really adorable

mahendharkhedhar
Автор

All the videos are awesome and very deeply a lot

sagarshekhar
Автор

Awesome job .. so thoroughly explained .. just loved it 🙌 👏 👍

deepmingle
Автор

Good explanation and really good content. Please make video tutorial on JAVAFX Concurrency if possible. Good going keep it up.

MrWicky
Автор

Excellent Video, something i was looking forward to.
There is some confusion at 5:19. It says Que type is LinkedBlockingQue for fixedThreadPool and singleThreadExecutor. Wouldn't it be better to useArrayBlockIngQue since we now the size before hand and it will no go beyond the mentioned size?
Anyone would like to comment ? Would be great if maker of this video can guide me in this matter :)

irshadahmad
Автор

Very well explained..understood the concept ..please upload videos on restful web services

balajibalu
join shbcf.ru