— Scott McNealy, Sun Microsystems Chairman, President and ceo


System.out.println(“back in main”)



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

System.out.println(“back in main”);
}
}
Calling sleep here will force the new 
thread to leave the currently-running 
state!
The main thread will become the 
currently-running 
thread again, and 
print 
out “back in main”. Then there will be a 
pause (for about two seconds) before we 
get to this line, which calls doMore() and 
prints out “top o’ the stack”
File Edit Window Help SnoozeButton 
% java ThreadTestDrive
back in main
top o’ the stack
% java ThreadTestDrive
back in main
top o’ the stack
% java ThreadTestDrive
back in main
top o’ the stack
% java ThreadTestDrive
back in main
top o’ the stack
% java ThreadTestDrive
back in main
top o’ the stack
This is what we want—a consistent order 
of print statements:
using 
Thread.sleep()


networking 
and
threads
you are here
4
503
Making and starting 
two threads
Threads have names. You can give your threads a name of 
your choosing, or you can accept their default names. But the 
cool thing about names is that you can use them to tell which 
thread is running. The following example starts two threads. 
Each thread has the same job: run in a loop, printing the 
currently-running thread’s name with each iteration.
public class RunThreads implements Runnable {
public static void main(String[] args) {
RunThreads runner = new RunThreads();
Thread alpha = new Thread(runner);
Thread beta = new Thread(runner);
alpha.setName(“Alpha thread”);

Download 40,57 Mb.

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