Java Reference
In-Depth Information
Figure 8.6
The output of the
Filler
and
Getter
threads for the
ExclusiveApplet
as they fill and retrieve a bin value in a
Box
object.
}
public void run () {
int value = 0;
for (int i=0; i < 10; i++) {
fNumber = fBox.get ();
}
} // run
} // class Getter
The snippet from
ExclusiveApplet
shown below creates a
Box
,a
Filler
,
and a
Getter
object and then starts the two threads. Figure 8.6 shows a typical
output. We see that the synchronization prevents a data race situation and the two
threads each complete their respective tasks.
public class
ExclusiveApplet
extends JApplet
implements Outputable, ActionListener
{
. ..Build the interface...
Search WWH ::
Custom Search