— Scott McNealy, Sun Microsystems Chairman, President and ceo


beta.setName(“Beta thread”)



Download 40,57 Mb.
Pdf ko'rish
bet464/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   460   461   462   463   464   465   466   467   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

beta.setName(“Beta thread”);
alpha.start();
beta.start();
}
public void 
run()
 {
for (int i = 0; i < 25; i++) {
String threadName = Thread.currentThread().getName();
System.out.println(threadName + “ is running”);
}
}
}
Make one Runnable instance.
Make two threads, with the same Runnable (the 
same job--we’ll talk more about the “two threads 
and one Runnable” in a few pages).
Name the threads.
Start the threads.
Each thread will run through this loop, 
printing its name each time.
What will happen?
Will the threads take turns? Will you see the thread names 
alternating? How often will they switch? With each iteration? 
After five iterations? 
You already know the answer: we don’t know! It’s up to the 
scheduler. And on your OS, with your particular JVM, on 
your CPU, you might get very different results.
Running under OS X 10.2 (Jaguar), with five or fewer 
iterations, the Alpha thread runs to completion, then 
the Beta thread runs to completion. Very consistent. Not 
guaranteed, but very consistent.
But when you up the loop to 25 or more iterations, things 
start to wobble. The Alpha thread might not get to complete 
all 25 iterations before the scheduler sends it back to 
runnable to let the Beta thread have a chance.
File Edit Window Help Centauri 
Alpha thread is running
Alpha thread is running
Alpha thread is running
Beta thread is running
Alpha thread is running
Beta thread is running
Beta thread is running
Beta thread is running
Beta thread is running
Beta thread is running
Beta thread is running
Beta thread is running

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   460   461   462   463   464   465   466   467   ...   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