— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet454/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   450   451   452   453   454   455   456   457   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

3
myThread.start();
Nothing happens until you call the Thread’s 
start() method. That’s when you go from 
having just a Thread instance to having a new 
thread of execution. When the new thread 
starts up, it takes the Runnable object’s 
run() method and puts it on the bottom of 
the new thread’s stack.
Run
nable obje
ct
Thread objec

Thread objec

Runn
able obj
ec

run()
launching a 
thread


networking 
and
threads
you are here
4
493
Every Thread needs a job to do.
A method to put on the new thread stack.
A Thread object needs a job. A job the thread will run when the 
thread is started. That job is actually the first method that goes on 
the new thread’s stack, and it must always be a method that looks 
like this:
 
public void run() {
// code that will be run by the new thread
 
}
How does the thread know which method to put at the bottom of 
the stack? Because Runnable defines a contract. Because Runnable 
is an interface. A thread’s job can be defined in any class that 
implements the Runnable interface. The thread cares only that you 
pass the Thread constructor an object of a class that implements 
Runnable.
When you pass a Runnable to a Thread constructor, you’re really 
just giving the Thread a way to get to a run() method. You’re giving 
the Thread its job to do.
Runnable is to a 
Thread what a job is to 
a worker. A Runnable 
is the job a thread is 
supposed to run.
A Runnable holds the 
method that goes on 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   450   451   452   453   454   455   456   457   ...   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