SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
LIFE CYCLE OFA
THREAD
CONTENT
S
NO
TOPIC
PAGE NO
1.
INTRODUCTION TO MULTITHREADED
PROGRAMMING 1
2. LIFE CYCLE OF ATHREAD 1
3. STATES OF A THREAD 2
4. THREAD PRIORITIES 3
5.
CREATE A THREAD BY IMPLEMENTING A
RUNNABLE INTERFACE 3
6. BASIC METHODS 4
7. BENEFITS OF MULTITHREADING 4
1 GO BACK
INTRODUCTION TO MULTITHREADED PROGRAMMING
Java is a multi-threaded programming language which means we can develop
multi-threaded program using Java.
A multi-threaded program contains two or more parts that can run concurrently and
each part can handle a different task at the same time.
By definition, multitasking is when multiple processes share common processing
resources such as a CPU.
Multi-threading extends the idea of multitasking into applications where you can
subdivide specific operations within a single application into individual threads.
Each of the threads can run in parallel. The OS divides processing time not only
among different applications, but also among each thread within an application.
Multi-threading enables you to write in a way where multiple activities can proceed
concurrently in the same program.
LIFE CYCLE OF A THREAD
A thread goes through various stages in its life cycle. For example, a thread is born,
started, runs, and then dies.
The following diagram shows the complete life cycle of a thread.
2 GO BACK
STATES OF A THREAD
A thread can be in any of the five following states
1. Newborn State: When a thread object is created a new thread is born
and said to be in Newborn state.
a. Runnable State: If a thread is in this state it means that the thread is
ready for execution and waiting for the availability of the processor. If all threads
in queue are of same priority then they are given time slots for execution in round
robin fashion
2. Running State: It means that the processor has given its time to the
thread for execution. A thread keeps running until the following conditions
occurs
a. Thread give up its control on its own and it can happen in the
following situations
i. A thread gets suspended using suspend() methodwhich
can only be revived with resume() method
ii. A thread is made to sleep for a specified period of timeusing
sleep(time) method, where time in milliseconds
iii. A thread is made to wait for some event to occur using wait ()
method. In this case a thread can be scheduled to run again
using notify () method.
b. A thread is pre-empted by a higher priority thread
3. Blocked State: If a thread is prevented from entering into runnable
state and subsequently running state, then a thread is said to be in Blocked state.
4. Dead State: A runnable thread enters the Dead or terminated state
when it completes its task or otherwise terminates.
3 GO BACK
THREAD PRIORITIES
Every Java thread has a priority that helps the operating system determine the order
in which threads are scheduled.
Java thread priorities are in the range between MIN_PRIORITY (a constant of 1)
and MAX_PRIORITY (a constant of 10). By default, every thread is given priority
NORM_PRIORITY (a constant of 5).
Threads with higher priority are more important to a program and should be
allocated processor time before lower-priority threads.
However, thread priorities cannot guarantee the order in which threads execute and
are very much platform dependent.
CREATE A THREAD BY IMPLEMENTING A RUNNABLE INTERFACE
If your class is intended to be executed as a thread then you can achieve this by
implementing a Runnable interface.
There are three basic steps
Step 1:
As a first step, you need to implement a run() method provided by
a Runnable interface. This method provides an entry point for the thread and you will put
your complete business logic inside this method. Following is a simple syntax of the run()
method
Public void run( );
Step 2:
As a second step, you will instantiate a Thread object using the following
constructor
Thread(Runnable threadObj, String threadName);
Where, threadObj is an instance of a class that implements the Runnable interface
and threadName is the name given to the new thread.
Step 3:
Once a Thread object is created, you can start it by calling start() method, which
executes a call to run( ) method. Following is a simple syntax of start() method
void start();
4 GO BACK
BASIC METHODS
Method Description
start() This method starts the execution of the thread and
JVM calls the run() method on the thread.
Sleep(int
milliseconds)
This method makes the thread sleep hence the thread's
execution will pause for milliseconds provided and
after that, again the thread starts executing. This help in
synchronization of the threads.
getName() It returns the name of the thread.
setPriority(int
newpriority)
It changes the priority of the thread.
yield () It causes current thread on halt and other threads to execute.
BENEFITS OF MULTITHREADING
1. Enables programmers to do multiple things at one time
 2. Programmers can divide a long program into threads and execute t
hem in parallel which eventually increases the speed of the program
execution
3. Improved performance and concurrency
4. Simultaneous access to multiple applications

More Related Content

PPT
Software quality assurance lecture 1
PPTX
Presentation on-exception-handling
PDF
Advance database systems (part 1)
PPTX
OOPS In JAVA.pptx
PPTX
Object Oriented Programming
PPTX
Artificial Intelligence in Education focusing on the Skills3.0 project
PPTX
Introduction to flowchart
PDF
Java Thread Synchronization
Software quality assurance lecture 1
Presentation on-exception-handling
Advance database systems (part 1)
OOPS In JAVA.pptx
Object Oriented Programming
Artificial Intelligence in Education focusing on the Skills3.0 project
Introduction to flowchart
Java Thread Synchronization

What's hot (20)

PDF
Java threads
PPT
Thread model in java
PPTX
Lock based protocols
PPTX
Sum of subset problem.pptx
PPTX
Java program structure
PPTX
Method overloading
PPTX
Deadlock ppt
PPTX
Graph coloring using backtracking
PPT
Applet life cycle
ODP
Multithreading In Java
PPT
Abstract class in java
PPTX
Static Members-Java.pptx
PPT
Method overriding
PPT
Object and class relationships
PPTX
Constructor in java
PPTX
Abstraction java
PDF
Java arrays
PPTX
Learning in AI
PPTX
Control statements in java
PDF
Java I/o streams
Java threads
Thread model in java
Lock based protocols
Sum of subset problem.pptx
Java program structure
Method overloading
Deadlock ppt
Graph coloring using backtracking
Applet life cycle
Multithreading In Java
Abstract class in java
Static Members-Java.pptx
Method overriding
Object and class relationships
Constructor in java
Abstraction java
Java arrays
Learning in AI
Control statements in java
Java I/o streams
Ad

Similar to Java thread life cycle (20)

PDF
Java Multithreading Interview Questions PDF By ScholarHat
PDF
Multithreading Introduction and Lifecyle of thread
PPTX
Multithreading in java
PPTX
Multithreading in java
PPTX
Multi threading
PPTX
Multithreading in java
PPT
Java And Multithreading
DOCX
Threadnotes
PPT
Chap2 2 1
PPTX
OOPS object oriented programming UNIT-4.pptx
PPTX
JAVA THEORY PPT.pptx on based up on the transaction
PPTX
Concept of Java Multithreading-Partially.pptx
PPT
Md09 multithreading
PPTX
unit3multithreadingppt-copy-180122162204.pptx
PPTX
unit3 Exception Handling multithreadingppt.pptx
PDF
Java Threads
PPTX
MULTI THREADING IN JAVA
PDF
JAVA 3.2.pdfhdfkjhdfvbjdbjfhjdfhdjhfjdfdjfhdjhjd
PPTX
MSBTE Computer Engineering JPR java. multi. threading.pptx
PPTX
Multithreading in Java Object Oriented Programming language
Java Multithreading Interview Questions PDF By ScholarHat
Multithreading Introduction and Lifecyle of thread
Multithreading in java
Multithreading in java
Multi threading
Multithreading in java
Java And Multithreading
Threadnotes
Chap2 2 1
OOPS object oriented programming UNIT-4.pptx
JAVA THEORY PPT.pptx on based up on the transaction
Concept of Java Multithreading-Partially.pptx
Md09 multithreading
unit3multithreadingppt-copy-180122162204.pptx
unit3 Exception Handling multithreadingppt.pptx
Java Threads
MULTI THREADING IN JAVA
JAVA 3.2.pdfhdfkjhdfvbjdbjfhjdfhdjhfjdfdjfhdjhjd
MSBTE Computer Engineering JPR java. multi. threading.pptx
Multithreading in Java Object Oriented Programming language
Ad

More from Archana Gopinath (20)

PDF
The Graph Abstract Data Type-DATA STRUCTURE.pdf
PPTX
Introduction-to-Binary-Tree-Traversal.pptx
PPTX
DNS-Translates domain names into IP addresses.pptx
PPTX
Data Transfer & Manipulation.pptx
PPTX
DP _ CO Instruction Format.pptx
PPTX
Language for specifying lexical Analyzer
PPTX
Implementation of lexical analyser
PPTX
A simple approach of lexical analyzers
PPTX
A Role of Lexical Analyzer
PPTX
minimization the number of states of DFA
PPTX
Regular Expression to Finite Automata
PPTX
Fundamentals of big data analytics and Hadoop
PPTX
Map reduce in Hadoop BIG DATA ANALYTICS
PPTX
Business intelligence
PPTX
PPTX
Programming with R in Big Data Analytics
PPTX
If statements in c programming
PPT
un Guided media
PPT
Guided media Transmission Media
PPTX
Main Memory RAM and ROM
The Graph Abstract Data Type-DATA STRUCTURE.pdf
Introduction-to-Binary-Tree-Traversal.pptx
DNS-Translates domain names into IP addresses.pptx
Data Transfer & Manipulation.pptx
DP _ CO Instruction Format.pptx
Language for specifying lexical Analyzer
Implementation of lexical analyser
A simple approach of lexical analyzers
A Role of Lexical Analyzer
minimization the number of states of DFA
Regular Expression to Finite Automata
Fundamentals of big data analytics and Hadoop
Map reduce in Hadoop BIG DATA ANALYTICS
Business intelligence
Programming with R in Big Data Analytics
If statements in c programming
un Guided media
Guided media Transmission Media
Main Memory RAM and ROM

Recently uploaded (20)

PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Machine learning based COVID-19 study performance prediction
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Empathic Computing: Creating Shared Understanding
NewMind AI Weekly Chronicles - August'25 Week I
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Machine learning based COVID-19 study performance prediction
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf

Java thread life cycle

  • 2. CONTENT S NO TOPIC PAGE NO 1. INTRODUCTION TO MULTITHREADED PROGRAMMING 1 2. LIFE CYCLE OF ATHREAD 1 3. STATES OF A THREAD 2 4. THREAD PRIORITIES 3 5. CREATE A THREAD BY IMPLEMENTING A RUNNABLE INTERFACE 3 6. BASIC METHODS 4 7. BENEFITS OF MULTITHREADING 4
  • 3. 1 GO BACK INTRODUCTION TO MULTITHREADED PROGRAMMING Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time. By definition, multitasking is when multiple processes share common processing resources such as a CPU. Multi-threading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing time not only among different applications, but also among each thread within an application. Multi-threading enables you to write in a way where multiple activities can proceed concurrently in the same program. LIFE CYCLE OF A THREAD A thread goes through various stages in its life cycle. For example, a thread is born, started, runs, and then dies. The following diagram shows the complete life cycle of a thread.
  • 4. 2 GO BACK STATES OF A THREAD A thread can be in any of the five following states 1. Newborn State: When a thread object is created a new thread is born and said to be in Newborn state. a. Runnable State: If a thread is in this state it means that the thread is ready for execution and waiting for the availability of the processor. If all threads in queue are of same priority then they are given time slots for execution in round robin fashion 2. Running State: It means that the processor has given its time to the thread for execution. A thread keeps running until the following conditions occurs a. Thread give up its control on its own and it can happen in the following situations i. A thread gets suspended using suspend() methodwhich can only be revived with resume() method ii. A thread is made to sleep for a specified period of timeusing sleep(time) method, where time in milliseconds iii. A thread is made to wait for some event to occur using wait () method. In this case a thread can be scheduled to run again using notify () method. b. A thread is pre-empted by a higher priority thread 3. Blocked State: If a thread is prevented from entering into runnable state and subsequently running state, then a thread is said to be in Blocked state. 4. Dead State: A runnable thread enters the Dead or terminated state when it completes its task or otherwise terminates.
  • 5. 3 GO BACK THREAD PRIORITIES Every Java thread has a priority that helps the operating system determine the order in which threads are scheduled. Java thread priorities are in the range between MIN_PRIORITY (a constant of 1) and MAX_PRIORITY (a constant of 10). By default, every thread is given priority NORM_PRIORITY (a constant of 5). Threads with higher priority are more important to a program and should be allocated processor time before lower-priority threads. However, thread priorities cannot guarantee the order in which threads execute and are very much platform dependent. CREATE A THREAD BY IMPLEMENTING A RUNNABLE INTERFACE If your class is intended to be executed as a thread then you can achieve this by implementing a Runnable interface. There are three basic steps Step 1: As a first step, you need to implement a run() method provided by a Runnable interface. This method provides an entry point for the thread and you will put your complete business logic inside this method. Following is a simple syntax of the run() method Public void run( ); Step 2: As a second step, you will instantiate a Thread object using the following constructor Thread(Runnable threadObj, String threadName); Where, threadObj is an instance of a class that implements the Runnable interface and threadName is the name given to the new thread. Step 3: Once a Thread object is created, you can start it by calling start() method, which executes a call to run( ) method. Following is a simple syntax of start() method void start();
  • 6. 4 GO BACK BASIC METHODS Method Description start() This method starts the execution of the thread and JVM calls the run() method on the thread. Sleep(int milliseconds) This method makes the thread sleep hence the thread's execution will pause for milliseconds provided and after that, again the thread starts executing. This help in synchronization of the threads. getName() It returns the name of the thread. setPriority(int newpriority) It changes the priority of the thread. yield () It causes current thread on halt and other threads to execute. BENEFITS OF MULTITHREADING 1. Enables programmers to do multiple things at one time 2. Programmers can divide a long program into threads and execute t hem in parallel which eventually increases the speed of the program execution 3. Improved performance and concurrency 4. Simultaneous access to multiple applications