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


Question 92: What is Cyclic Barrier?



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

Question 92: What is Cyclic Barrier?
Answer: CyclicBarrier is used to make multiple threads wait for each
other to reach a common barrier point. It is used mainly when
multiple threads perform some calculation and the result of these
threads needs to be combined to form the final output.
All the threads that wait for each other to reach the barrier are called
parties, CyclicBarrier is created with a number of parties to wait for,
and the threads wait for each other at the barrier by calling
cyclicBarrier.await() method which is a blocking method and it blocks
until all threads have called await().
The barrier is called Cyclic because it can be re-used after the
waiting threads are released, by calling cyclicBarrier.reset() method
which resets barrier to the initial state.
A CyclicBarrier supports an optional Runnable command that is run
once per barrier point, after the last thread in the party arrives, but
before any threads are released. This barrier action is useful for
updating shared-state before any of the parties continue.


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
92\color1.png


The CyclicBarrier uses an all-or-none breakage model for failed
synchronization attempts: If a thread leaves a barrier point
prematurely because of interruption, failure, or timeout, all other
threads waiting at that barrier point will also leave abnormally via
BrokenBarrierException (or InterruptedException if they too were
interrupted at about the same time).
Example: One thread is adding first 5 natural numbers to the list, the
other thread is adding next 5 numbers to the list and we will perform
an addition of all these numbers to compute the sum of first 10
natural numbers


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
92\color2.png


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


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
92\color4.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
92\color5.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
92\color6.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
92\color7.png


Output:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
92\output.png



Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   65   66   67   68   69   70   71   72   ...   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