Thread:- A thread is a single sequential flow of control within a program. As we know that, all Java programs have at least one thread, known as main thread. It is created by the JVM at the program’s start, when the main() method is invoked with main thread.
In Java, creating a thread is by implementing an interface (Runnable) and extending a class (Thread). Every Java thread is created and controlled by the java.lang.Thread class.
When a thread is created, it is assigned a priority. Thread to execute with higher priority is executed first, followed by lower-priority threads.
The JVM stops executing threads under the following conditions:
- If exit method has been invoked and authorized by the security manager
- All daemon threads of program have died.
A thread is a lightweight sub process, a smallest unit of processing. It is a separate path of execution.
Priority of Thread:- Each thread have a priority. Priorities are represented by a number between 1 and 10.
There are 3 constants in java Thread class:-
- public static int MIN_PRIORITY
- public static int NORM_PRIORITY
- public static int MAX_PRIORITY