Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview


new ArrayBlockingQueue(100); ThreadFactory



Download 7,31 Mb.
Pdf ko'rish
bet67/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   63   64   65   66   67   68   69   70   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

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 it all together:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
88\color3.png


Question 89: Tell something about
awaitTermination() method in executor
Answer: This method blocks until all tasks have completed execution
after a shutdown request, or the timeout occurs, or the current thread
is interrupted, whichever happens first.


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
89\color.png


It returns true if this executor is terminated and false if the timeout is
elapsed before termination.
Question 90: Difference between shutdown() and
shutdownNow() methods of executor
Answer: An executor will not shut down automatically even when
there is no task to process. It will stay alive and wait for new work. It
will keep the JVM running.
When shutdown() method is called on an executor, then the executor
will not accept new tasks and it will wait for the currently executing
tasks to finish.
When shutdownNow() is called, it tries to interrupt the running
threads and shutdown the executor immediately. However, there is
no guarantee that all the running threads will be stopped at the same
time.
One good way to shutdown an executor is to use both of these
methods along with awaitTermination(). With this approach, the
executor will stop accepting new tasks and waits up to the specified
duration for all running tasks to be completed. If the time expires, it
will shutdown immediately.


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
90\color.png



Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   63   64   65   66   67   68   69   70   ...   89




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish