— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet485/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   481   482   483   484   485   486   487   488   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

synchronization 
questions


networking 
and
threads
you are here
4
523
Code Kitchen
This is the last version of the BeatBox! 
It connects to a simple MusicServer so that you can 
send and receive beat patterns with other clients.
The code is really long, so the complete listing is 
actually in Appendix A.
your message gets sent to 
the other players, along 
with your current beat 
pattern, when you hit 
“sendIt”
Andy: groove #2
Chris: groove2 revised
Nigel: dance beat
dance beat
incoming messages from 
players. Click one to load 
the pattern that goes 
with it, and then click 
‘Start’ to play it.


524
 
chapter 15
A working Java program is scrambled up on the fridge. Can 
you add the code snippets on the next page to the empty 
classes below, to make a working Java program that pro-
duces the output listed? Some of the curly braces fell on the 
floor and they were too small to pick up, so feel free to add as 
many of those as you need!
File Edit Window Help Sewing
% java TestThreads
one 98098
two 98099
Exercise
Code Magnets
class ThreadOne
class Accum {
class ThreadTwo
public class TestThreads {
Bonus Question:
Why do you think we used the 
modifiers we did in the Accum class? 
exercise: 
Code Magnets


networking 
and
threads
you are here
4
525
try {
Thread.sleep(50);
Thread.sleep(50);
Code Magnets, continued..
counter += add;
return a;
implements Runnable {
public void run() {
return counter;
one.start();
a.updateCounter(1000);
Thread one = new Thread(t1);
try {
public static void main(String [] args) {
for(int x=0; x < 99; x++) {
} catch(InterruptedException ex) { }
private static Accum a = new Accum();
} catch(InterruptedException ex) { }
implements Runnable {
Accum a = Accum.getAccum();
Accum a = Accum.getAccum();
public void run() {
for(int x=0; x < 98; x++) {
two.start();
ThreadOne t1 = new ThreadOne();
ThreadTwo t2 = new ThreadTwo();
public void updateCounter(int add) {
private Accum() { }
public int getCount() {
System.out.println(“two 
“+a.getCount());
System.out.println(“one “+a.getCount());
public static Accum getAccum() {
private int counter = 0;
a.updateCounter(1);
Thread two = new Thread(t2);



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   481   482   483   484   485   486   487   488   ...   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