ptg7068951
WHAT YOU’LL LEARN IN
THIS HOUR:
.Using an interface with a
program
.Creating threads
.Starting,stopping,and
pausing threads
.Catching errors
A computer term used often to describe the hectic pace of daily life is
multitasking, which means to do more than one thing at once—such as
browsing the Web at your desk while participating in a conference call and
doing butt crunch exercises. Amultitasking computer is one that can run
more than one program at a time.
One sophisticated feature of the Java language is the ability to write pro-
grams that can multitask, which is made possible through a class of objects
called threads.
Threads
In a Java program, each of the simultaneous tasks the computer handles is
called a threadand the overall process is called multithreading. Threading is
useful in animation and many other programs.
Threads are a way to organize a program so that it does more than one
thing at a time. Each task that must occur simultaneously is placed in its
own thread, and this often is accomplished by implementing each task as a
separate class.
Threads are represented by the Threadclass and the Runnableinterface,
which are both part of the java.langpackage of classes. Because they
belong to this package, you don’t have to use an importstatement to make
them available in your programs.
One of the simplest uses of the Threadclass is to slow down how fast a
program does something.
HOUR 19
Creating a Threaded Program