— Scott McNealy, Sun Microsystems Chairman, President and ceo


doMore( ) Thread Thread



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

doMore( )
Thread
Thread
void join()
void start()
static void sleep()
A thread (lower-case ‘t’) is a separate thread of execution. 
That means a separate call stack. Every Java application 
starts up a main thread—the thread that puts the 
main() method on the bottom of the stack. The JVM 
is responsible for starting the main thread (and other 
threads, as it chooses, including the garbage collection 
thread). As a programmer, you can write code to start 
other threads of your own.
main( )
x.foo( )
y.bar( )
x.baz( )
main thread
another thread 
started by the code
Thread (capital ‘T’) is a class that 
represents a thread of execution. 
It has methods for starting a 
thread, joining one thread with 
another, and putting a thread to 
sleep. (It has more methods; these 
are just the crucial ones we need 
to use now).
java.lang.Thread 
class
A thread is a separate 
‘thread of execution’. 
In other words, a 
separate call stack. 
A Thread is a Java 
class that represents 
a thread.
To make a thread, 
make a Thread.
threads and 
Thread


networking 
and
threads
you are here
4
491
What does it mean to have more than 
one call stack?
With more than one call stack, you get the appearance of having 
multiple things happen at the same time. In reality, only a true 
multiprocessor system can actually do more than one thing at a 
time, but with Java threads, it can appear that you’re doing several 
things simultaneously. In other words, execution can move back 
and forth between stacks so rapidly that you feel as though all stacks 
are executing at the same time. Remember, Java is just a process 
running on your underlying OS. So first, Java itself has to be ‘the 
currently executing process’ on the OS. But once Java gets its 
turn to execute, exactly what does the JVM run? Which bytecodes 
execute? Whatever is on the top of the currently-running stack! 
And in 100 milliseconds, the currently executing code might switch 
to a different method on a different stack. 
One of the things a thread must do is keep track of which statement 
(of which method) is currently executing on the thread’s stack. 
It might look something like this:

Download 40,57 Mb.

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