What is a thread?
Defines and provides an overview of a thread in a Java program
A thread is a lightweight process that runs on the JVM and provides an environment for a program's execution. The JVM's system threads handle tasks like I/O and memory management, among others. Each Java class is processed by a main thread of execution. The thread exits along with the program or application that initiated it. All the Java programs we have seen so far have followed a sequential execution path. That is, the flow of control (branches, iteration, method calls and etc) are dictated by the code itself. Such programs run on a single thread (not counting system threads) called the main thread. Java allows developers to spawn other threads from the main thread, i.e. split the main thread into many threads. These multiple threads may then be made to carry out independent tasks in the application simultaneously. Such multi-threaded programs are execute asynchronously and they are no longer bound to a single sequential execution path.
Threads increase efficiency by splitting tasks. An application may contain I/O operations, network operations or other tasks that take quite some time to complete. If such an application runs on a single thread, all unrelated tasks that are below the high-cost tasks in the control flow do not start execution until the execution of the slow (or potentially non-responsive) operations is complete. A multi-threaded application would split its tasks in such a way that one thread takes care of slow operations while another takes care of the other unrelated tasks so that both run simultaneously.
Using multiple threads in programs is also known as concurrent programming. The Java platform has always supported multi-threaded programs. Some high level APIs have been added to the basic Thread support in Java since Version 5.0. A thread in a Java program may be created through the class Thread (java.lang.thread) that implements the Runnable interface. A Thread is not a program on its own, it simply specifies the manner in which an application should execute.