What is thread class in java?
The ability of a program to concurrently execute multiple
regions of code provides capabilities that are difficult or
impossible to achieve with strictly sequential languages.
Sequential object-oriented languages send messages (make method
calls) and then block or wait for the operation to complete.
Programmers are already familiar with concurrent processes,
possibly without
recognizing them. For example, operating systems usually have
many processes
running to handle printing, updating the display, receiving mail
from the network, and so on. In contrast, most programming
languages do not promote the use of concurrent operations within
one application. At best, programmers have access to a few library
calls to launch and control multiple operations.
Java provides language-level and library support for
threads--independent
sequences of execution within the same program that share the
same code and data address space. Each thread has its own stack to
make method calls and store local variables.
Most applications that use threads are a form of simulation or
have a graphical
user interface, but threads in general have the following
advantages over sequential programming:
Threads support concurrent operations.
For example, Server applications can handle multiple clients by
launching a thread to deal with each client.
Long computations or high-latency disk and network operations
can be handled in the background without disturbing foreground
computations or screen updates.
Threads often result in simpler programs.
In sequential programming, updating multiple displays normally
requires a big
while-loop that performs small parts of each display update.
Unfortunately,
this loop basically simulates an operating system scheduler. In
Java, each view
can be assigned a thread to provide continuous updates.
Programs that need to respond to user-initiated events can set
up service
routines to handle the events without having to insert code in
the main routine
to look for these events.
Threads provide a high degree of control.
Imagine launching a complex computation that occasionally takes
longer than
is satisfactory. A "watchdog" thread can be activated that will
"kill" the
computation if it becomes costly, perhaps in favor of an
alternate,
approximate solution. Note that sequential programs must muddy
the
computation with termination code, whereas, a Java program can
use thread
control to non-intrusively supervise any operation.
Threaded applications exploit parallelism.
A computer with multiple CPUs can literally execute multiple
threads on
different functional units without having to simulating
multi-tasking ("time
sharing").
On some computers, one CPU handles the display while another
handles
computations or database accesses, thus, providing extremely
fast user
interface response times.