Java Reference
In-Depth Information
ferent runs of the application. But under all implementations, invoking
yield can give other threads a more equitable chance at getting cycles.
Two other factors affect the behavior of this program (and many like it
that try to demonstrate scheduling behavior). The first is that println
uses synchronization, so the different threads must all contend for the
same lock.
The second factor is that there are three threads in the program, not
two. The main thread has to create and start the two Babble tHReads and
that means that it contends with them for scheduling as well. It is en-
tirely possible that the first Babble tHRead will run to completion before
the main thread even gets the chance to create a second Babble tHRead.
Exercise 14.7 : Run Babble multiple times and examine the output: Is it
always the same? If possible, run it on different systems and compare.
 
Search WWH ::




Custom Search