— Scott McNealy, Sun Microsystems Chairman, President and ceo


Option One:  Poll the server every 20 seconds 2



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

1
Option One: 
Poll the server every 20 seconds
2
Option Two: 
Read something in from the server each time the user 
sends a message.
Pros: Do-able, very easy
Cons: Stupid. Why choose such an arbitrary time to check for messages? What if a user is 
a lurker and doesn’t send anything?
3
Option Three: 
Read messages as soon as they’re sent from the server
Pros: Most efficient, best usability
Cons: How do you do you do two things at the same time? Where would you put this code? 
You’d need a loop somewhere that was always waiting to read from the server. But where 
would that go? Once you launch the GUI, nothing happens until an event is fired by a GUI 
component.
improving the 
chat client


networking 
and
threads
you are here
4
489
You know by now that we’re 
going with option three.
In Java you really CAN 
walk and chew gum at 
the same time.
We want something to run continuously, 
checking for messages from the server, 
but without interrupting the user’s ability to 
interact with the GUI! So while the user is 
happily typing new messages or scrolling 
through the incoming messages, we 
want something behind the scenes to keep 
reading in new input from the server.
That means we fi nally need a new thread. 
A new, separate stack
We want everything we did in the Send-
Only version (version one) to work the 
same way, while a new 
process runs along 
side that reads information from the 
server and displays it in the incoming text 
area.
Well, not quite. Unless you have multiple 
processors on your computer, each new 
Java thread is not actually a separate 
process running on the OS. But it almost 
feels as though it is.
Multithreading in Java
Java has multiple threading built right 
into the fabric of the language. And it’s a 
snap to make a new thread of execution:

Download 40,57 Mb.

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