Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview by Arora Jatin
Author:Arora, Jatin [Arora, Jatin]
Language: eng
Format: epub, pdf
Published: 2020-10-18T16:00:00+00:00
Core and Max Pool sizes:
A ThreadPoolExecutor will automatically adjust the pool size according to the bounds set by corePoolSize and maximumPoolSize
When a new task is submitted to the executor then:
-
If the number of threads running are less than the corePoolSize, a new thread is created to handle the request
-
If the number of threads running are more than corePoolSize but less than maximumPoolSize then a new thread will be created only if the queue is full
Letâs understand this with an example:
You have defined the core pool size as 5, maximum pool size as 10 and the queue capacity as 100. Now as tasks are coming in, new threads will be created up to 5, then other new tasks will be added to queue until it reaches 100. Now when the queue is full and if new tasks are coming in, threads will be created up to the maximumPoolSize i.e. 10. Once all the threads are in use and the queue is also full, the new tasks will be rejected. As the queue reduces, so does the number of active threads.
Keep Alive Time and TimeUnit:
When the number of threads are greater than the core size, this is the maximum time that excess idle threads will wait for new tasks before terminating. It is used to avoid the overhead of creating a new thread.
Letâs understand this with an example:
You have defined the core pool size as 5 and maximum pool size as 15 and all the 15 threads are getting used at the moment. Now when the threads are getting finished with their work, the excess 10 threads (15-5) become idle and eventually die. To avoid these 10 threads being killed too quickly, we can specify the keep alive time for these by using the keepAliveTime parameter in the ThreadPoolExecutor constructor. If you have given its value as 1 and time unit as TimeUnit.MINUTE, each thread will wait for 1 min after it had finished executing a task. Basically, it is waiting for a new task to be assigned. If it is not given any task, it would let itself complete. And in the end, the executor will be left with the core threads (5).
BlockingQueue:
The queue to use for holding tasks before they are executed. This queue will hold only the Runnable tasks submitted by the execute method, you can use a ArrayBlockingQueue or LinkedBlockingQueue like:
BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(100);
ThreadFactory:
The factory to use when the executor creates a new thread. Using thread factories removes hardwiring of calls to new Thread , enabling applications to use special thread subclasses, priorities, etc.
RejectedExecutionHandler:
This handler is used when a task is rejected by the executor because all the threads are busy and the queue is full.
When this handler is not provided and the task submitted to execute() method is rejected, then an unchecked RejectedExecutionException is thrown.
But adding a handler is a good practice to follow, there is a method:
void rejectedExecution(Runnable r , ThreadPoolExecutor executor );
This method will be invoked by ThreadPoolExecutor when execute() cannot accept a task.
Putting
Download
Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview by Arora Jatin.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
What's Done in Darkness by Kayla Perrin(26951)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(20847)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20600)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20531)
The Fifty Shades Trilogy & Grey by E L James(19448)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19371)
Shot Through the Heart by Mercy Celeste(19227)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17379)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17340)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(17175)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(17089)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16704)
The Subtle Art of Not Giving a F*ck by Mark Manson(14816)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14432)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(14207)
Cozy crochet hats: 7 Stylish and Beginner-Friendly Patterns from Baby Beanies to Trendy Bucket Hats by Vanilla Lazy(13483)
Scorched Earth by Nick Kyme(13081)
Reichel W. Numerical methods for Electrical Engineering, Meteorology,...2022 by Unknown(12961)
Drei Generationen auf dem Jakobsweg by Stein Pia(11246)