— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet476/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   472   473   474   475   476   477   478   479   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

public void go() {
doStuff();
synchronized(this) {
criticalStuff();
moreCriticalStuff();
}
}
synchronizing 
methods


networking 
and
threads
you are here
4
515
A
1
Thread A runs for awhile
Attempt to enter the increment() method.
The method is synchronized, so 
get the key
for this object
Put the value of balance into variable i.
Balance is 0, so i is now 0.
Set the value of balance to the result of i + 1.
Now balance is 1.
Return the key 
(it completed the increment() method).
Re-enter the increment() method and 
get the key
.
Put the value of balance into variable i.
Balance is 1, so i is now 1.
[now thread A is sent back to runnable, but since it has not 
completed the synchronized method, Thread A keeps the key] 
B
2
Thread B is selected to run
Attempt to enter the increment() method. The method is 
synchronized, so we need to get the key.
The key is not available.
[now thread B is sent into a ‘object lock not available lounge]
A
3
Thread A runs again, picking up where it left off
(remember, it still has the key)
Set the value of balance to the result of i + 1.
Now balance is 2.
Return the key
.
[now thread A is sent back to runnable, but since it 
has completed the increment() method, the thread 
does NOT hold on to the key]
B
4
Thread B is selected to run
Attempt to enter the increment() method. The method is 
synchronized, so we need to get the key.
This time, the key IS available, get the key.
Put the value of balance into variable i.
[continues to run...]



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   472   473   474   475   476   477   478   479   ...   555




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