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

Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
JayasankarPR2
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
Elizabeth Thomas
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Java I/O
Java I/OJava I/O
Thread model in java
Thread model in javaThread model in java
Thread model in java
AmbigaMurugesan
 
Io streams
Io streamsIo streams
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
babak danyal
 
Computer Science:Java jdbc
Computer Science:Java jdbcComputer Science:Java jdbc
Computer Science:Java jdbc
St Mary's College,Thrissur,Kerala
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Arafat Hossan
 
Java threading
Java threadingJava threading
Java threading
Chinh Ngo Nguyen
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
Vipin Yadav
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Java Threads
Java ThreadsJava Threads
Java Threads
M Vishnuvardhan Reddy
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
parag
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
Mindfire Solutions
 
Thread priority in java
Thread priority in javaThread priority in java
Thread priority in java
Rakesh Mittal
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
Raja Sekhar
 

What's hot (20)

Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java I/O
Java I/OJava I/O
Java I/O
 
Thread model in java
Thread model in javaThread model in java
Thread model in java
 
Io streams
Io streamsIo streams
Io streams
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Computer Science:Java jdbc
Computer Science:Java jdbcComputer Science:Java jdbc
Computer Science:Java jdbc
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java threading
Java threadingJava threading
Java threading
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
 
Java threads
Java threadsJava threads
Java threads
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Thread priority in java
Thread priority in javaThread priority in java
Thread priority in java
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 

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

Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
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...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
Java unit 12
Java unit 12Java unit 12
Java unit 12
Shipra Swati
 
201 core java interview questions oo ps interview questions - javatpoint
201 core java interview questions   oo ps interview questions - javatpoint201 core java interview questions   oo ps interview questions - javatpoint
201 core java interview questions oo ps interview questions - javatpoint
ravi tyagi
 
Java introduction
Java introductionJava introduction
Java introduction
The icfai university jaipur
 
Lec 3 01_aug13
Lec 3 01_aug13Lec 3 01_aug13
Lec 3 01_aug13
Palak Sanghani
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDE
Shweta Oza
 
159747608 a-training-report-on
159747608 a-training-report-on159747608 a-training-report-on
159747608 a-training-report-on
homeworkping7
 
Spring boot competitive tests
Spring boot competitive testsSpring boot competitive tests
Spring boot competitive tests
SkillPracticalEdTech
 
Spring boot competitive tests
Spring boot competitive testsSpring boot competitive tests
Spring boot competitive tests
SkillPracticalEdTech
 
JVM, JRE and Javac are the main part for the java program
 JVM, JRE and Javac are the main part for the java program JVM, JRE and Javac are the main part for the java program
JVM, JRE and Javac are the main part for the java program
siyaram ray
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
loidasacueza
 
java_threads.ppt
java_threads.pptjava_threads.ppt
java_threads.ppt
ssuserec53e73
 
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Edureka!
 
Lecture 3
Lecture 3Lecture 3
B.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: AppetB.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: Appet
Assistant Professor, Shri Shivaji Science College, Amravati
 
Java-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oopsJava-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oops
buvanabala
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
Madhura Bhalerao
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
Khaled AlGhazaly
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
Robert Scholte
 

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

Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Java unit 12
Java unit 12Java unit 12
Java unit 12
 
201 core java interview questions oo ps interview questions - javatpoint
201 core java interview questions   oo ps interview questions - javatpoint201 core java interview questions   oo ps interview questions - javatpoint
201 core java interview questions oo ps interview questions - javatpoint
 
Java introduction
Java introductionJava introduction
Java introduction
 
Lec 3 01_aug13
Lec 3 01_aug13Lec 3 01_aug13
Lec 3 01_aug13
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDE
 
159747608 a-training-report-on
159747608 a-training-report-on159747608 a-training-report-on
159747608 a-training-report-on
 
Spring boot competitive tests
Spring boot competitive testsSpring boot competitive tests
Spring boot competitive tests
 
Spring boot competitive tests
Spring boot competitive testsSpring boot competitive tests
Spring boot competitive tests
 
JVM, JRE and Javac are the main part for the java program
 JVM, JRE and Javac are the main part for the java program JVM, JRE and Javac are the main part for the java program
JVM, JRE and Javac are the main part for the java program
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
java_threads.ppt
java_threads.pptjava_threads.ppt
java_threads.ppt
 
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
B.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: AppetB.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: Appet
 
Java-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oopsJava-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oops
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
 

More from Edureka!

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

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
zjhamm304
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
FilipTomaszewski5
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 

Recently uploaded (20)

Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 

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