Multithreading is a feature of Java that allows two or more portions of a program to run concurrently, maximizing CPU utilization. Each component of such a program is referred to as a thread. Thus, threads are lightweight processes within processes.
When a Java program starts, one thread runs instantly. This is commonly referred to as the program's main thread because it is performed when the program starts.
To create a new thread in Java, first instantiate a class that extends the Thread class or implements the Runnable interface, and then call the start() method to start the new thread's execution.
In Java, a thread containing a loop is created by enclosing a loop within the run() method of a Thread subclass or a Runnable implementation and then beginning the thread to execute the loop concurrently.
In Java, a thread can be in any of the following states. The states are: