Java Reference
In-Depth Information
using threads. Single-threaded systems usually provide an illusion of
multiple threads either by using interrupts or by polling. Polling mixes
the display and user input parts of an application. In particular, the dis-
play code must be written so it will poll often enough to respond to user
input in fractions of a second. Display code either must ensure that dis-
play operations take minimal time or must interrupt its own operations
to poll. The resulting mixture of two unrelated functional aspects of a
program leads to complex and often unmaintainable code.
These kinds of problems are more easily solved in a multithreaded sys-
tem. One thread of control updates the display with current data, and
another thread responds to user input. If user input is complexfor ex-
ample, filling out a form display code can run independently until it re-
ceives new data. In a polling model, either display updates must pause
for complex input or complicated handshaking must be used so that dis-
play updates can continue while the user types data into the form. Such
a model of shared control within a process can be directly supported in a
multithreaded system instead of being handcrafted for each new polling
case.
This chapter describes the basic constructs, classes, and methods that
control multithreading in the Java programming language, but it cannot
teach you effective multithreaded program design. The package
java.util.concurrent and its subpackages provide higher-level concur-
rency utilities to ease the task of writing sophisticated multithreaded
programs, but again the detailed use of such tools is beyond the scope
of this bookan overview is given in Section 25.9.1 on page 733 . You can
read Concurrent Programming in Java , Second Edition, a book in this
series, to get advice on how to create well-designed multithreaded pro-
grams. " Further Reading " on page 755 has other useful references to
give you a background in thread and synchronization design.
 
Search WWH ::




Custom Search