CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Java Thread Lifecycle

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor

Java Thread Lifecycle

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Published: March 14, 2021 ยท 3 min read ยท 0 Comments
Share: in X

Threads are one of the most important concepts in Java programming. They allow us to run multiple tasks simultaneously, which can improve the performance of our applications. However, it’s important to understand the Java thread lifecycle in order to use them effectively.

In this blog post, we will discuss the different states that a thread can be in, and how it can move between these states. We will also discuss some of the events that can cause a thread to change state.

Let’s understand the following image first.

thread life cycle in java

A thread in Java can be in one of the following states:

New

This is the state that a thread is in when we create an instance of Thread class but before the invocation of start() method.

Runnable

The thread is in runnable state after invocation of start() method, but the thread scheduler has not selected it to be the running thread. So basically, this is the state after calling the start() method and before calling the run() method.

Running

The thread is in running state if the thread scheduler has selected it and called a run() method.

Blocked

This is the state when the thread is still alive, but is currently not running or not eligible to run.

Terminated

A thread is in terminated or dead state when its run() method exits. This is the end of the thread lifecycle in Java.

A thread can move between states in a number of ways. For example, a thread can move from the New state to the Runnable state when the start() method is called on it. A thread can move from the Runnable state to the Blocked state when it tries to acquire a lock on a shared resource that is already locked by another thread. A thread can move from the Runnable state to the Waiting state when it calls the wait() method.

FAQs

What is the Java thread lifecycle?

The Java thread lifecycle represents the various states a thread can be in during its execution. These states include new, runnable, running, blocked, and terminated.

What is the “New” state in the thread lifecycle?

The “New” state is the initial state of a thread. In this state, the thread is created, but it has not yet started its execution.

How does a thread transition from the “New” state to the “Runnable” state?

A thread transitions from the “New” state to the “Runnable” state when the start() method is called on the thread object. This method initiates the thread’s execution.

What causes a thread to enter the “Blocked” state?

A thread enters the “Blocked” state when it’s waiting for a resource that’s currently held by another thread. It will remain in this state until the resource becomes available.

How does a thread enter the “Terminated” state?

A thread enters the “Terminated” state when its run() method finishes executing or when it’s explicitly terminated using the Thread class’s interrupt() or stop() methods.

Can a thread transition from “Terminated” back to any other state?

No, once a thread is in the “Terminated” state, it cannot return to any other state in the thread lifecycle. It has completed its execution.

Related Posts:

  • Thread in Java
  • Control Statements in Java
  • Inner Thread Communication in Java
  • Thread Deadlock in Java
  • MySQL Commands for Developers
  • Create Thread in Java
Tags:javalanguage-fundamentalsthread
Was this article helpful?
โ† Previous ArticleJRadioButton in Java Swing
Next Article โ†’Constant in Java

Recent Posts

  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
  • Complete Guide to JaCoCo: How to Measure Java Code Coverage Accurately
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
ยฉ 2026 CoderSathi. All rights reserved. Privacy Policy ยท Sitemap