9.4 Summary
Thread scheduling is a gray area of Java programming because actual
scheduling models are not defined by the Java specification. As a
result, scheduling behavior can (and does) vary on different
machines.
In a general sense, threads have a priority, and threads with a
higher-priority tend to run more often that threads with a lower
priority. The degree to which this is true depends on the underlying
operating system; Windows operating systems give more precedence to
the thread priority while Unix-style operating systems give more
precedence to letting all threads have a significant amount of CPU
time.
For the most part, this thread scheduling doesn't
matter: the information we've looked at in this
chapter is important for understanding what's going
on in your program, but there's not much you can do
to change the way it works. In the next two chapters,
we'll look at other kinds of thread scheduling and,
using the information we've just learned, see how to
make optimal use of multiple threads on multiple CPUs.
9.4.1 Example Classes
Here is the class name and Ant target for the example in this chapter:
|
Description
|
Main Java class
|
Ant target
|
|---|
|
Recursive Fibonacci Calculator
|
javathreads.examples.ch09.example1.ThreadTest nThreads
FibCalcValue
|
ch9-ex1
|
The Fibonacci test requires command-line arguments that specify the
number of threads to run simultaneously and the value to calculate.
In the Ant script, those arguments are defined by these properties:
<property name="nThreads" value="10"/>
<property name="FibCalcValue" value="20"/>
|