站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Java Threads, Third Edition

9.4 Summary - Java Threads, Third Edition

Previous Section  < Day Day Up >  Next Section

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"/>

    Previous Section  < Day Day Up >  Next Section