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


Question 83: What will be output of below program



Download 7,31 Mb.
Pdf ko'rish
bet61/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   57   58   59   60   61   62   63   64   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

Question 83: What will be output of below program
where one synchronized method is calling another
synchronized method?


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


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


Output:
C:\Users\j
jatin\Deskto
p\Different
Versions\All
_Photos\Qu
estion
83\output.p
One thing to remember here is that Java synchronized keyword is
re-entrant in nature, it means if a synchronized method calls another
synchronized method which requires same lock then current thread
which is holding the lock can enter into that method without acquiring
lock.
Question 84: Programs related to synchronized and
static synchronized methods
There are some confusing programs that interviewer can ask where
some methods are static synchronized and some methods are non-
static synchronized, and sometimes they are calling each other, so
let’s discuss those.
Scenario 1 : There are 2 threads that are calling 2 different static
synchronized methods.
Here, these 2 threads will block each other, as only one lock per
class exists. So, these 2 static synchronized methods will not be
executed at the same time.


Program:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
84\Scenario 1\color1.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
84\Scenario 1\color2.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
84\Scenario 1\color3.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
84\Scenario 1\color4.png


Output:
C:\Users\jjatin\Desktop\Different
Versions\All_Photos\Question 84\Scenario
1\output.png

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   57   58   59   60   61   62   63   64   ...   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