Strona startowa Ludzie pragną czasami się rozstawać, żeby móc tęsknić, czekać i cieszyć się z powrotem.Król Edyp chciał uniknąć swego losu, naznaczonego mu przez bogów, zanim jeszcze przyszedł na świat...Gracze rozchodzili się z wolna, podążając kolejno w ślad za Joharranem, ku przeciwległemu krańcowi tarasu...wzroku— Jak to nie obchodzi?! — krzyknął kapitan Giles nie kryjąc już oburzenia, które zresztą przejawiało się u niego w sposób opanowany i spokojny...- Jedenastu - poprawił Adam, ale oświadczenie żony zrobiło mu wyraźną przyjemność...property set to ’hidden’ are considered to have no visible content...RysMorgan jęknęła...Kotuko rozciął rzemień krępujący psy, a one — nie posiadając się z radości — rzuciły mu się na pierś, starając się w psim języku wyjaśnić,...Tak się pogrążył we wspomnieniach, które wypływały z niego bez żadnej kontroli, a jednak w cudownie subtelnym porządku, że Kyaren również zaczęła...
 

Ludzie pragną czasami się rozstawać, żeby móc tęsknić, czekać i cieszyć się z powrotem.

Feedback
Chapter 13: Concurrency
775

3. In Chapter 8, locate the GreenhouseController.java example,
which consists of four files. In Event.java, the class Event is
based on watching the time. Change Event so that it is a Thread,
and change the rest of the design so that it works with this new
Thread-based Event. Feedback
4. Modify the previous exercise so that the java.util.Timer class is
used to run the system. Feedback
5. Modify SimpleThread.java so that all the threads are daemon
threads, and verify that the program ends as soon as main( ) is
able to exit. Feedback
6. Demonstrate that java.util.Timer scales to large numbers by
creating a program that generates many Timer objects which
perform some simple task when the timeout completes (if you
want to get fancy you can jump forward to the “Windows and
Applets” chapter and use the Timer objects to draw pixels on the
screen, but printing to the console is sufficient).
7. Demonstrate that a synchronized method in a class can call a
second synchronized method in the same class, which can then
call a third synchronized method in the same class. Create a
separate Thread object that invokes the first synchronized
method.
8. Create two Thread subclasses, one with a run( ) that starts up
and then calls wait( ). The other class’ run( ) should capture the
reference of the first Thread object. Its run( ) should call
notifyAll( ) for the first thread after some number of seconds
have passed, so the first thread can print a message. Feedback
9. Create an example of a “busy wait.” One thread sleeps for awhile
and then sets a flag to true. The second thread watches that flag
inside a while loop (this is the “busy wait”) and when the flag
becomes true, sets it back to false and reports the change to the
console. Note how much wasted time the program spends inside
the “busy wait,” and create a second version of the program that
uses wait( ) instead of the “busy wait.”
776
Thinking in Java
www.BruceEckel.com

10. Modify Restaurant.java to use notifyAll( ) and observe any
difference in behavior.
11. Modify Restaurant.java so that there are multiple
WaitPersons, and indicate which one gets each Order. Note
that you must use notifyAll( ) instead of notify( ) in this case.
12. Modify Restaurant.java so that multiple WaitPersons
generate order requests to multiple Chefs, who produce orders
and notify the WaitPerson that generated the request. You’ll
need to use queues for both incoming order requests and outgoing
orders.
13. Modify the previous exercise to add Customer objects which are
also threads. The Customers will place order requests with
WaitPersons, who give the requests to the Chefs, who fulfill the
orders and notify the appropriate WaitPerson, who gives it to
the appropriate Customer.
14. Modify PipedIO.java so that Sender reads and sends lines from
a text file.
15. Change DiningPhilosophers.java so that the philosophers just
pick the next available chopstick (when a philosopher is done with
their chopsticks, they drop them into a bin. When a philosopher
wants to eat, they take the next two available chopsticks from the
bin). Does this eliminate the possibility of deadlock? Can you re-
introduce deadlock by simply reducing the number of available
chopsticks?
16. Inherit a class from java.util.Timer and implement the
requestStop( ) method as in Stopping.java.
17. Modify SimpleThread.java so that all threads receive an
interrupt( ) before they are completed.
18. Solve the flow-control problem. The sender must not overflow the
receiver’s buffer, which can happen if the sender is faster than the
receiver. If the receiver is faster than sender, then it must not read
the same data more than once. Produce flow control using wait( )
and notify( ). Consider the above scenarios and also the case
Chapter 13: Concurrency
777

where you are not aware of the relative speeds of the sender and
receiver.
778
Thinking in Java
www.BruceEckel.com

14: Creating
Windows
& Applets
A fundamental design guideline is “make simple things
easy, and difficult things possible.” 1
The original design goal of the graphical user interface (GUI) library in
Java 1.0 was to allow the programmer to build a GUI that looks good on
all platforms. That goal was not achieved. Instead, the Java 1.0 Abstract
Window Toolkit (AWT) produced a GUI that looked equally mediocre on
all systems. In addition, it was restrictive: you could use only four fonts
and you couldn’t access any of the more sophisticated GUI elements that
exist in your operating system. The Java 1.0 AWT programming model is
also awkward and non-object-oriented. A student in one of my seminars
(who had been at Sun during the creation of Java) explained why: the
original AWT had been conceptualized, designed, and implemented in a
month. Certainly a marvel of productivity, and also an object lesson in
why design is important. Feedback
The situation improved with the Java 1.1 AWT event model, which takes a