| Multithreading is a fundamental feature of the Java language
specification. The creators of Java understood the importance
of multithreading and provided easy to use features for application
developers. Two of these features, the Thread class and the
Runnable interface, will be covered shortly. |
| |
| Multithreading is not the same as multiprocessing.
The latter involves the use of two or more processors (CPUs).
Multithreading involves the sharing of a single processor and
the interleaving of CPU time as shown by the following diagram: |
| |
|
| |
| Because there is only one processor, only one instruction
can be executed at a time. In a Java program, the decision as
to which thread is currently executing is determined by the JVM. |
| |
| Multithreading is used to execute even the simplest Java program.
Even if a program doesn't create its own threads, the Java Virtual
Machine creates multiple threads to support the program.
One thread performs the processing of the main() method.
Other threads manage and monitor system resources.
The garbage collector, for example, is always running as a low-priority thread. |