SlideShare une entreprise Scribd logo
1  sur  13
Multithreading in Java
Multitasking - Multithreading
Hello Class

Handling multiple tasks – Multitasking
Ability to initiate multiple processes - Multithreading
Process & Threads
Process

Threads
Spell Checker in word can be considered as a thread
An application running is called a process, a process can have multiple threads.
Example - Thread

NFS

ROAD RASH

Games are best example for applying Multithreading
What are Threads?
• Two or more tasks executing concurrently within a single
•
•
•
•

•

program.
It is an independent path of execution in a program.
You always have thread in your application even if you don’t
create it.
main method is a thread and also known as main thread.
Threads are scheduled by OS to be processed by the
Processor, so its behavior depends on the OS. It cannot be
guaranteed about threads execution.
In java it is created & controlled by java.lang.Thread class
Creating Threads
Thread t = new Thread();

Thread

Just creates Thread Object

t.start();

public void run(){
// starting point for thread
}

-To start the thread start method should be invoked
-No guarantee about when it will start, depends on OS scheduler
Starting up with Threads
• There are two ways to create thread in java;
• By Extending the Thread class (java.lang.Thread)
• instance of a class that inherits from thread

• Implement the Runnable interface (java.lang.Runnable)
• instance of thread where you pass the behavior of the thread into the

thread constructor

• Let us see examples
Lifecycle of a Thread
Thread - sleep()
• A method used to tell the current thread to sleep for certain
•
•
•
•

time.
Sleep method accepts time in milliseconds.
Can throw InterruptedException.
Cannot guarantee that a thread goes to sleep for specified
time.
Once sleep state is complete, the thread can move to
Runnable or Running state.
Action Listener
Action Listener Example
• When you create a button on a Frame, and when you press it

and something happens that is called ActionListener. We tell
the button to do something when it is clicked. Or it can be
performed on TextBox, CheckBox, Radio Buttons, etc.
ActionListener
• Action Listeners are the event handlers to be implemented,

that you decide what to should be done or performed on
certain user operations. The event occurs whenever an
action is performed by user.
• Example 1
• Example 2
Done!

Contenu connexe

Tendances

Tendances (20)

Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Java threads
Java threadsJava threads
Java threads
 
Multi threading
Multi threadingMulti threading
Multi threading
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Life cycle-of-a-thread
Life cycle-of-a-threadLife cycle-of-a-thread
Life cycle-of-a-thread
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
OOP java
OOP javaOOP java
OOP java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
12 multi-threading
12 multi-threading12 multi-threading
12 multi-threading
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrency
 
Multithreading in-java
Multithreading in-javaMultithreading in-java
Multithreading in-java
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in Java
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 

En vedette

En vedette (18)

Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
Threads
ThreadsThreads
Threads
 
Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading Presentation
 
Ch5: Threads (Operating System)
Ch5: Threads (Operating System)Ch5: Threads (Operating System)
Ch5: Threads (Operating System)
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programming
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)
 
Thread
ThreadThread
Thread
 
Thread lifecycle
Thread lifecycleThread lifecycle
Thread lifecycle
 
Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
 
Usage concurrence in java
Usage concurrence in javaUsage concurrence in java
Usage concurrence in java
 
Java threads - part 3
Java threads - part 3Java threads - part 3
Java threads - part 3
 
Java threads - part 2
Java threads - part 2Java threads - part 2
Java threads - part 2
 
Java threads - part 1
Java threads - part 1Java threads - part 1
Java threads - part 1
 
Main Memory
Main MemoryMain Memory
Main Memory
 
Java 8. Thread pools
Java 8. Thread poolsJava 8. Thread pools
Java 8. Thread pools
 
Java Multithreading
Java MultithreadingJava Multithreading
Java Multithreading
 
OS - Thread
OS - ThreadOS - Thread
OS - Thread
 

Similaire à Thread presentation

OOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxOOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxArulmozhivarman8
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
Java multithreading
Java multithreadingJava multithreading
Java multithreadingMohammed625
 
Multithreading
MultithreadingMultithreading
MultithreadingF K
 
Lecture 23-24.pptx
Lecture 23-24.pptxLecture 23-24.pptx
Lecture 23-24.pptxtalha ijaz
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingBadar Waseer
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptxTREXSHyNE
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptxmadan r
 
Multithreading.pptx
Multithreading.pptxMultithreading.pptx
Multithreading.pptxssuserfcae42
 
econtent thread in java.pptx
econtent thread in java.pptxecontent thread in java.pptx
econtent thread in java.pptxramyan49
 
Multithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of threadMultithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of threadKartik Dube
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in javaElizabeth alexander
 
Threads in java, Multitasking and Multithreading
Threads in java, Multitasking and MultithreadingThreads in java, Multitasking and Multithreading
Threads in java, Multitasking and Multithreadingssusere538f7
 

Similaire à Thread presentation (20)

OOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxOOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptx
 
Thread
ThreadThread
Thread
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java multithreading
Java multithreadingJava multithreading
Java multithreading
 
Java
JavaJava
Java
 
multithreading
multithreadingmultithreading
multithreading
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java
JavaJava
Java
 
Chap2 2 1
Chap2 2 1Chap2 2 1
Chap2 2 1
 
Lecture 23-24.pptx
Lecture 23-24.pptxLecture 23-24.pptx
Lecture 23-24.pptx
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented Programming
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptx
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
 
Multithreading.pptx
Multithreading.pptxMultithreading.pptx
Multithreading.pptx
 
econtent thread in java.pptx
econtent thread in java.pptxecontent thread in java.pptx
econtent thread in java.pptx
 
Multithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of threadMultithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of thread
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in java
 
Threads in java, Multitasking and Multithreading
Threads in java, Multitasking and MultithreadingThreads in java, Multitasking and Multithreading
Threads in java, Multitasking and Multithreading
 

Plus de AAshish Ojha

Bad UI design Example
Bad UI design ExampleBad UI design Example
Bad UI design ExampleAAshish Ojha
 
School management system
School management systemSchool management system
School management systemAAshish Ojha
 
Library management system
Library management systemLibrary management system
Library management systemAAshish Ojha
 
Customer management
Customer managementCustomer management
Customer managementAAshish Ojha
 
Airline solution system proposal
Airline solution system   proposalAirline solution system   proposal
Airline solution system proposalAAshish Ojha
 
process&models in UML
process&models in UMLprocess&models in UML
process&models in UMLAAshish Ojha
 

Plus de AAshish Ojha (7)

Bad UI design Example
Bad UI design ExampleBad UI design Example
Bad UI design Example
 
School management system
School management systemSchool management system
School management system
 
Library management system
Library management systemLibrary management system
Library management system
 
Customer management
Customer managementCustomer management
Customer management
 
Airline solution system proposal
Airline solution system   proposalAirline solution system   proposal
Airline solution system proposal
 
Pc remote
Pc remotePc remote
Pc remote
 
process&models in UML
process&models in UMLprocess&models in UML
process&models in UML
 

Dernier

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Dernier (20)

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Thread presentation

  • 2. Multitasking - Multithreading Hello Class Handling multiple tasks – Multitasking Ability to initiate multiple processes - Multithreading
  • 3. Process & Threads Process Threads Spell Checker in word can be considered as a thread An application running is called a process, a process can have multiple threads.
  • 4. Example - Thread NFS ROAD RASH Games are best example for applying Multithreading
  • 5. What are Threads? • Two or more tasks executing concurrently within a single • • • • • program. It is an independent path of execution in a program. You always have thread in your application even if you don’t create it. main method is a thread and also known as main thread. Threads are scheduled by OS to be processed by the Processor, so its behavior depends on the OS. It cannot be guaranteed about threads execution. In java it is created & controlled by java.lang.Thread class
  • 6. Creating Threads Thread t = new Thread(); Thread Just creates Thread Object t.start(); public void run(){ // starting point for thread } -To start the thread start method should be invoked -No guarantee about when it will start, depends on OS scheduler
  • 7. Starting up with Threads • There are two ways to create thread in java; • By Extending the Thread class (java.lang.Thread) • instance of a class that inherits from thread • Implement the Runnable interface (java.lang.Runnable) • instance of thread where you pass the behavior of the thread into the thread constructor • Let us see examples
  • 8. Lifecycle of a Thread
  • 9. Thread - sleep() • A method used to tell the current thread to sleep for certain • • • • time. Sleep method accepts time in milliseconds. Can throw InterruptedException. Cannot guarantee that a thread goes to sleep for specified time. Once sleep state is complete, the thread can move to Runnable or Running state.
  • 11. Action Listener Example • When you create a button on a Frame, and when you press it and something happens that is called ActionListener. We tell the button to do something when it is clicked. Or it can be performed on TextBox, CheckBox, Radio Buttons, etc.
  • 12. ActionListener • Action Listeners are the event handlers to be implemented, that you decide what to should be done or performed on certain user operations. The event occurs whenever an action is performed by user. • Example 1 • Example 2
  • 13. Done!