Chapter 13 |
Thread concepts
One of the powerful features of Java is its built-in support for multithreading. A multithreaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources especially when a computer has multiple CPUs. Each such part of a program called thread. Threads can be executed simultaneously in multiprocessor systems. In single-processor systems the multiple threads share CPU time, known as time sharing, and the operating system is responsible for scheduling and allocating resources to them.
The advantage of multithreaded programs is that such programs are more responsive and interactive. For example, a good word processor lets us print or save a file while we are typing. In some cases, multithreaded programs run faster than single-threaded programs even on single-processor systems. Java provides exceptionally good support for creating and running threads and for locking resources to prevent conflicts.
Chapter 13 |