Tuesday, 29 November 2016

Java Tutorial : Java Threads (Life cycle of a Thread in Java | Java thread life cycle_V2)

Master Java Multithreading!

Subscribe to our channel for step-by-step Core Java tutorials and concurrency deep dives!

👉 Click Here to Subscribe

Demystifying the Java Thread Life Cycle

Multithreading is a core capability in Java that enables programs to execute multiple operations simultaneously. A thread progresses through a defined series of states throughout its execution. Gaining a clear understanding of these states is vital for writing safe, performant concurrent code.

The Key Thread States Explained

1. New State

When a thread object is created using new MyThread(), it begins in the New state. It exists in memory but has not yet started running or interacting with the thread scheduler.

2. Runnable State

Calling the start() method transitions the thread into the Runnable state. In this state, the thread is ready to execute and waits in the pool for CPU resources allocated by the operating system.

3. Running State

When the thread scheduler picks the runnable thread, it enters the Running state and executes the code defined inside its run() method.

4. Blocked / Waiting States

Threads can temporarily pause their active execution:

  • Blocked: The thread is waiting to acquire a monitor lock to enter a synchronized block or method.
  • Waiting / Timed Waiting: Pauses execution until notified by another thread or until a sleep/join timer expires.

5. Terminated (Dead) State

When the run() method execution completes or an uncaught exception terminates the thread, it moves into the Terminated state and cannot be run again.

Related Video Tutorials


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=EXtn0gflrYw&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge 
Java Tutorial : Java Threads (Life cycle of a Thread in Java | Java thread life cycle_V2) 
Java Tutorial : Java Threads (Life cycle of a Thread in Java | Java thread life cycle_V2) 
Java Tutorial : Java Threads (Life cycle of a Thread in Java | Java thread life cycle_V2) 
Java Tutorial : Java Threads (Life cycle of a Thread in Java | Java thread life cycle_V2) 
Java Tutorial : Java Threads (Life cycle of a Thread in Java | Java thread life cycle_V2) 
Java Tutorial : Java Threads (Life cycle of a Thread in Java | Java thread life cycle_V2) 
See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Tutorials