— Scott McNealy, Sun Microsystems Chairman, President and ceo


public static void main(String[] args) {



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

public static void main(String[] args) {
... 

1
The JVM calls the main() method.
main()
Runnable r = new MyThreadJob();
Thread t = new Thread(r);
t.start();
Dog d = new Dog();
 
2
main() starts a new thread. The main 
thread is temporarily frozen while the new 
thread starts running.
3
The JVM switches between the new 
thread (user thread A) and the original 
main thread, until both threads complete.
main thread
main thread
run()
user thread A
main()
t.start()
the active thread
a new thread starts 
and becomes the active 
thread
main thread
main()
Dog()
user thread A
run()
x.go()
you’ll learn what 
this means in just 
a moment...
the active thread again


492
 
chapter 15
Make a Runnable object (the thread’s job)
1
Runnable threadJob = new MyRunnable();
How to launch a new thread:
Runnable is an interface you’ll learn about on the next page. 
You’ll write a class that implements the Runnable interface, 
and that class is where you’ll define the work that a thread 
will perform. In other words, the method that will be run 
from the thread’s new call stack.
Make a Thread object (the worker) and 
give it a Runnable (the job)
2
Thread myThread = new Thread(threadJob);
Pass the new Runnable object to the Thread constructor. 
This tells the new Thread object which method to put on 
the bottom of the new stack—the Runnable’s run() method. 
Start the Thread

Download 40,57 Mb.

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