0 votes
in Java by
What is Thread in Java?

1 Answer

0 votes
by (4.4k points)

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:-

  1. public static int MIN_PRIORITY
  2. public static int NORM_PRIORITY
  3. public static int MAX_PRIORITY


Share:- Whatsapp Facebook Facebook

Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.