SlideShare a Scribd company logo
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java String
01
02
03
05
06
07
What is a Java Thread?
Thread Lifecycle
Creating a Thread
Main Thread
Multi Threading
Thread Pool
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
What is a Java Thread?
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
What is a Java Thread?
Thread is a lightweight sub process
Contains a separate path of execution
A thread is created & controlled by the java.lang.Thread class
It is the smallest independent unit of a program
Every Java program contains at least one thread
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Thread Life-Cycle
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Thread Lifecycle
New
Runnable
Running
Terminated
Waiting
A Java thread can lie only in
one of the shown states at
any point of time
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Thread Lifecycle
New
Runnable
Running
Terminated
Waiting
A new thread begins its life cycle in this state & remains here until the program
starts the thread. It is also known as a born thread.
New
Once a newly born thread starts, the thread comes under runnable state. A thread
stays in this state is until it is executing its task.
Runnable
In this state a thread starts executing by entering run() method and the yield()
method can send them to go back to the Runnable state.
Running
A thread enters this state when it is temporarily in an inactive state i.e it is still
alive but is not eligible to run. It is can be in waiting, sleeping or blocked state.
Waiting
A runnable thread enters the terminated state when it completes its task or
otherwise terminates.
Terminated
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Creating a Thread
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
public interface Runnable
public class Thread
extends Object
implements Runnable
Creating A Thread
A thread in Java can be created using two ways
Runnable InterfaceThread Class
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Runnable InterfaceThread Class
1. Create a Thread class
2. Override run() method
3. Create object of the class
4. Invoke start() method to
execute the custom threads run()
public class MyThread extends Thread {
public void run(){
System.out.println(“Edureka’s Thread…");
}
public static void main(String[] args) {
MyThread obj = new MyThread();
obj.start();
}
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Runnable InterfaceThread Class
1. Create a Thread class implementing
Runnable interface
2. Override run() method
3. Create object of the class
4. Invoke start() method using the
object
public class MyThread implements Runnable {
public void run(){
System.out.println(“Edureka’s Thread…");
}
public static void main(String[] args) {
Thread t = new Thread(new MyThread());
t.start();
}
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Runnable InterfaceThread Class vs
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Runnable InterfaceThread Class vs
✓ Each Thread creates its unique object ✓ Each Thread creates its unique object
✓ More memory consumption ✓ More memory consumption
✓ A class extending Thread class can’t extend any
other class
✓ Along with Runnable a class can implement any
other interface
✓ Thread class is extended only if there is a need
of overriding other methods of it
✓ Runnable is implemented only if there is a need of
special run method
✓ Enables tight coupling ✓ Enables loose coupling
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Main Thread
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Main Thread
Subtitle for arrow graphic
It is executed whenever a Java program starts
Every program must contain this thread for its execution to take place
Java main Thread is needed because of the following reasons
Main thread is the most important thread of a Java Program
2. It must be the last thread to finish execution i.e when the main thread stops program terminates
1. From this other “child” threads are spawned
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Main Thread
Main Thread Other Demon Threads
Child Thread A Child Thread B
Child Thread C
JVM
start() start()
start()start()
start()
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Multi Threading In Java
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Multi – Threading
Multi threading is the ability of a program to run two or more threads concurrently, where each thread can handle
a different task at the same time making optimal use of the available resources
Main Thread Main Thread Main Thread
Main Thread
start() start() start()
switching switching
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Thread Pool
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Task Task Task Task Task
Application
Queue
Thread
Thread
ThreadTask Finished
Thread
AssignmentNew Task
Thread Pool
Java thread pool manages the pool of worker threads and contains a queue that keep the
tasks waiting to get executed
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Thread Methods
Creating Multiple
Threads
Joining Threads Thread.sleep()
Inter Thread
Communication
Daemon Thread
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For Beginners | Edureka

More Related Content

What's hot (20)

PDF
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
DOCX
JDK,JRE,JVM
Cognizant
 
PPTX
Advance Java Topics (J2EE)
slire
 
PDF
Java Virtual Machine - Internal Architecture
subnesh
 
PPTX
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
shamnasain
 
PPT
Java Input Output and File Handling
Sunil OS
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PDF
A seminar report on core java
Aisha Siddiqui
 
PDF
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Edureka!
 
PPTX
Asynchronous programming in C#
Bohdan Pashkovskyi
 
PDF
Maven基礎
Toshio Takiguchi
 
PPT
Core java concepts
Ram132
 
PDF
Spring boot introduction
Rasheed Waraich
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
PDF
WebAssemblyのWeb以外のことぜんぶ話す
Takaya Saeki
 
PDF
Spring AMQP × RabbitMQ
Keisuke Nishitani
 
PDF
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Edureka!
 
PPTX
Java8勉強会
賢太郎 前多
 
PPTX
Presentation on Core java
mahir jain
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
JDK,JRE,JVM
Cognizant
 
Advance Java Topics (J2EE)
slire
 
Java Virtual Machine - Internal Architecture
subnesh
 
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
shamnasain
 
Java Input Output and File Handling
Sunil OS
 
Spring Framework - Core
Dzmitry Naskou
 
A seminar report on core java
Aisha Siddiqui
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Edureka!
 
Asynchronous programming in C#
Bohdan Pashkovskyi
 
Maven基礎
Toshio Takiguchi
 
Core java concepts
Ram132
 
Spring boot introduction
Rasheed Waraich
 
Spring boot Introduction
Jeevesh Pandey
 
WebAssemblyのWeb以外のことぜんぶ話す
Takaya Saeki
 
Spring AMQP × RabbitMQ
Keisuke Nishitani
 
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Edureka!
 
Java8勉強会
賢太郎 前多
 
Presentation on Core java
mahir jain
 

Similar to Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For Beginners | Edureka (20)

PDF
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Edureka!
 
PPTX
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
PDF
Java unit 12
Shipra Swati
 
PDF
201 core java interview questions oo ps interview questions - javatpoint
ravi tyagi
 
PPTX
Java introduction
The icfai university jaipur
 
PDF
Lec 3 01_aug13
Palak Sanghani
 
PPTX
How to run java program without IDE
Shweta Oza
 
DOCX
159747608 a-training-report-on
homeworkping7
 
DOCX
Spring boot competitive tests
SkillPracticalEdTech
 
DOCX
Spring boot competitive tests
SkillPracticalEdTech
 
PDF
JVM, JRE and Javac are the main part for the java program
siyaram ray
 
PPT
topic_presentation_java_threads_example.ppt
ShitalBahale2
 
PPT
java threads for easy learn and develop
pavanrock859
 
DOCX
Unit of competency
loidasacueza
 
PDF
Lecture 3
Debasish Pratihari
 
PDF
B.Sc. III(VI Sem) Advance Java Unit2: Appet
Assistant Professor, Shri Shivaji Science College, Amravati
 
PPTX
Java-1st.pptx about Java technology before oops
buvanabala
 
PPTX
1.introduction to java
Madhura Bhalerao
 
PDF
Top 50 Java Interviews Questions | Tutort Academy - Course for Working Profes...
Tutort Academy
 
PPT
Basic java part_ii
Khaled AlGhazaly
 
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Edureka!
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
Java unit 12
Shipra Swati
 
201 core java interview questions oo ps interview questions - javatpoint
ravi tyagi
 
Java introduction
The icfai university jaipur
 
Lec 3 01_aug13
Palak Sanghani
 
How to run java program without IDE
Shweta Oza
 
159747608 a-training-report-on
homeworkping7
 
Spring boot competitive tests
SkillPracticalEdTech
 
Spring boot competitive tests
SkillPracticalEdTech
 
JVM, JRE and Javac are the main part for the java program
siyaram ray
 
topic_presentation_java_threads_example.ppt
ShitalBahale2
 
java threads for easy learn and develop
pavanrock859
 
Unit of competency
loidasacueza
 
B.Sc. III(VI Sem) Advance Java Unit2: Appet
Assistant Professor, Shri Shivaji Science College, Amravati
 
Java-1st.pptx about Java technology before oops
buvanabala
 
1.introduction to java
Madhura Bhalerao
 
Top 50 Java Interviews Questions | Tutort Academy - Course for Working Profes...
Tutort Academy
 
Basic java part_ii
Khaled AlGhazaly
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 

Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For Beginners | Edureka

  • 1. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
  • 2. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java String 01 02 03 05 06 07 What is a Java Thread? Thread Lifecycle Creating a Thread Main Thread Multi Threading Thread Pool
  • 3. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training What is a Java Thread?
  • 4. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training What is a Java Thread? Thread is a lightweight sub process Contains a separate path of execution A thread is created & controlled by the java.lang.Thread class It is the smallest independent unit of a program Every Java program contains at least one thread
  • 5. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java Thread Life-Cycle
  • 6. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Thread Lifecycle New Runnable Running Terminated Waiting A Java thread can lie only in one of the shown states at any point of time
  • 7. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Thread Lifecycle New Runnable Running Terminated Waiting A new thread begins its life cycle in this state & remains here until the program starts the thread. It is also known as a born thread. New Once a newly born thread starts, the thread comes under runnable state. A thread stays in this state is until it is executing its task. Runnable In this state a thread starts executing by entering run() method and the yield() method can send them to go back to the Runnable state. Running A thread enters this state when it is temporarily in an inactive state i.e it is still alive but is not eligible to run. It is can be in waiting, sleeping or blocked state. Waiting A runnable thread enters the terminated state when it completes its task or otherwise terminates. Terminated
  • 8. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Creating a Thread
  • 9. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training public interface Runnable public class Thread extends Object implements Runnable Creating A Thread A thread in Java can be created using two ways Runnable InterfaceThread Class
  • 10. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Runnable InterfaceThread Class 1. Create a Thread class 2. Override run() method 3. Create object of the class 4. Invoke start() method to execute the custom threads run() public class MyThread extends Thread { public void run(){ System.out.println(“Edureka’s Thread…"); } public static void main(String[] args) { MyThread obj = new MyThread(); obj.start(); }
  • 11. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Runnable InterfaceThread Class 1. Create a Thread class implementing Runnable interface 2. Override run() method 3. Create object of the class 4. Invoke start() method using the object public class MyThread implements Runnable { public void run(){ System.out.println(“Edureka’s Thread…"); } public static void main(String[] args) { Thread t = new Thread(new MyThread()); t.start(); }
  • 12. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Runnable InterfaceThread Class vs
  • 13. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Runnable InterfaceThread Class vs ✓ Each Thread creates its unique object ✓ Each Thread creates its unique object ✓ More memory consumption ✓ More memory consumption ✓ A class extending Thread class can’t extend any other class ✓ Along with Runnable a class can implement any other interface ✓ Thread class is extended only if there is a need of overriding other methods of it ✓ Runnable is implemented only if there is a need of special run method ✓ Enables tight coupling ✓ Enables loose coupling
  • 14. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java Main Thread
  • 15. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java Main Thread Subtitle for arrow graphic It is executed whenever a Java program starts Every program must contain this thread for its execution to take place Java main Thread is needed because of the following reasons Main thread is the most important thread of a Java Program 2. It must be the last thread to finish execution i.e when the main thread stops program terminates 1. From this other “child” threads are spawned
  • 16. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java Main Thread Main Thread Other Demon Threads Child Thread A Child Thread B Child Thread C JVM start() start() start()start() start()
  • 17. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Multi Threading In Java
  • 18. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Multi – Threading Multi threading is the ability of a program to run two or more threads concurrently, where each thread can handle a different task at the same time making optimal use of the available resources Main Thread Main Thread Main Thread Main Thread start() start() start() switching switching
  • 19. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Thread Pool
  • 20. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Task Task Task Task Task Application Queue Thread Thread ThreadTask Finished Thread AssignmentNew Task Thread Pool Java thread pool manages the pool of worker threads and contains a queue that keep the tasks waiting to get executed
  • 21. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Thread Methods Creating Multiple Threads Joining Threads Thread.sleep() Inter Thread Communication Daemon Thread