SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
Core Java

Debasish Pratihari

Thread


A thread is the basic unit to which the operating
system allocates processor time.



Threads are useful to execute more or less
independent code segments concurrently of a
program.



Is knows as light-weight process.



Threads are always owned and managed by
operating system.



Every program has at least one thread.

User Thread


A user thread has a life-time of its own.



It is not depended on the thread that creates it.



It can continue execution after the thread that
created has ended.

Daemon Thread


Is a background thread that sub-ordinate to the
thread that creates it



When the thread that created the daemon
thread ends, the daemon thread dies with it.



A thread can be set to daemon before it starts



Threads

created

from

daemon

thread

are

daemon by default.

Lecture/core/thread1/20

Page #1

feel the Technology…
Core Java

Debasish Pratihari

Process


It has its own address space.



A process can’t access another process’s
memory .



Each process provides the resources needed to
execute a program.



Threads belongs to same process shares same
address space.



A process has at least one thread of execution.

Thread Objects:


Each thread is associated with an instance of
the class Thread



There are two ways for using thread object
 Directly controlling thread
 Using executor

Creating Thread
 Provide a Runnable Object
class Lakshya implements Runnable{
--}


Sub class Thread
class Lakshya extends Thread{
--}

Lecture/core/thread1/20

Page #2

feel the Technology…
Core Java

Debasish Pratihari

Thread State:


New Born State: When we create a Thread
Object then a Thread is born.



Runnable State: When we call the start( )
method on a thread then thread is in the
Runnable state i.e., the threads in Runnable
state are all waiting in a queue for the
availability of CPU attention or their turns to
come.



Running State: When a thread got the time of
CPU then it starts execution for a particular
interval of time (time slice) this state is called as
Running state.



Blocked state: A thread is in the blocked state
when it is prevented to entered into Runnable
state.



Dead state: This is the end of life of a thread,
when a thread completes execution comes to
the dead state. Also we can dead state by
calling stop( ) method.

New
Born

Start ( )

sleep ( )

Runnable
State

Stop ( )
Scheduling

Dead
State

Lecture/core/thread1/20

Running
State

Block
State
after time-slice
or
yield( )

Page #3

feel the Technology…
Core Java


Debasish Pratihari

A Thread enters into blocked state under the
following situation.






By sleeping a thread.
If a thread is waiting for I/O operation.
If a thread is Interrupted.
If a thread is waiting for lock available.

Thread Life-Cycle
25%
New
Born
start( )

start ( )
notify( )/ notifyAll ( )

Runnable
State

wait lock available
I/O complete
after t time

Scheduling
mechanism

after time
slice
sleep( )
wait( )

Running
State

wait for Lock
wait for I/O
sleep( t )

B
L
O
C
K
E
D
S
T
A
T
E

Dead
State

Lecture/core/thread1/20

Page #4

feel the Technology…

Weitere ähnliche Inhalte

Was ist angesagt?

Multithreading
MultithreadingMultithreading
Multithreading
backdoor
 
Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded Applications
Bharat17485
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
parag
 

Was ist angesagt? (19)

Java Multithreading
Java MultithreadingJava Multithreading
Java Multithreading
 
Thread presentation
Thread presentationThread presentation
Thread presentation
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Life cycle-of-a-thread
Life cycle-of-a-threadLife cycle-of-a-thread
Life cycle-of-a-thread
 
Thread model in java
Thread model in javaThread model in java
Thread model in java
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
Intro To .Net Threads
Intro To .Net ThreadsIntro To .Net Threads
Intro To .Net Threads
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in Java
 
Multithreading in-java
Multithreading in-javaMultithreading in-java
Multithreading in-java
 
Java Thread & Multithreading
Java Thread & MultithreadingJava Thread & Multithreading
Java Thread & Multithreading
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded Applications
 
Java threading
Java threadingJava threading
Java threading
 
Threads in Java
Threads in JavaThreads in Java
Threads in Java
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Multithreading Concepts
Multithreading ConceptsMultithreading Concepts
Multithreading Concepts
 
Java thread
Java threadJava thread
Java thread
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 

Andere mochten auch

Coral Exodo - 06.05.07
Coral Exodo - 06.05.07Coral Exodo - 06.05.07
Coral Exodo - 06.05.07
Jubrac Jacui
 
Migration Intro
Migration IntroMigration Intro
Migration Intro
dazza50
 
維基經濟學
維基經濟學維基經濟學
維基經濟學
sdfvb
 
Culto De Ferias - 26.07.07
Culto De Ferias - 26.07.07Culto De Ferias - 26.07.07
Culto De Ferias - 26.07.07
Jubrac Jacui
 

Andere mochten auch (20)

Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Chapter 2: Operating System Structures
Chapter 2: Operating System StructuresChapter 2: Operating System Structures
Chapter 2: Operating System Structures
 
Coral Exodo - 06.05.07
Coral Exodo - 06.05.07Coral Exodo - 06.05.07
Coral Exodo - 06.05.07
 
Presentatie Starterslift Breda - Online marketing
Presentatie Starterslift Breda - Online marketingPresentatie Starterslift Breda - Online marketing
Presentatie Starterslift Breda - Online marketing
 
Codemotion twitter programming
Codemotion twitter programmingCodemotion twitter programming
Codemotion twitter programming
 
JIPDay 2005: Xlet Java Programming
JIPDay 2005: Xlet Java ProgrammingJIPDay 2005: Xlet Java Programming
JIPDay 2005: Xlet Java Programming
 
小企业金融业务品牌推广方案 Push(v4.0)
小企业金融业务品牌推广方案 Push(v4.0)小企业金融业务品牌推广方案 Push(v4.0)
小企业金融业务品牌推广方案 Push(v4.0)
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Migration Intro
Migration IntroMigration Intro
Migration Intro
 
Clive Shepherd at LP2010
Clive Shepherd at LP2010Clive Shepherd at LP2010
Clive Shepherd at LP2010
 
Joanne jacobs at LP2010
Joanne jacobs at LP2010Joanne jacobs at LP2010
Joanne jacobs at LP2010
 
280 slides
280 slides280 slides
280 slides
 
Scenario exercise 2014 mid atlantic technical communication conference DDeBoard
Scenario exercise 2014 mid atlantic technical communication conference DDeBoardScenario exercise 2014 mid atlantic technical communication conference DDeBoard
Scenario exercise 2014 mid atlantic technical communication conference DDeBoard
 
Developing Policy for Emerging Technologies
Developing Policy for Emerging TechnologiesDeveloping Policy for Emerging Technologies
Developing Policy for Emerging Technologies
 
Pattern Learning
Pattern LearningPattern Learning
Pattern Learning
 
KDE: a solution for business environments
KDE: a solution for business environmentsKDE: a solution for business environments
KDE: a solution for business environments
 
維基經濟學
維基經濟學維基經濟學
維基經濟學
 
Mobile Tv
Mobile TvMobile Tv
Mobile Tv
 
Culto De Ferias - 26.07.07
Culto De Ferias - 26.07.07Culto De Ferias - 26.07.07
Culto De Ferias - 26.07.07
 

Ähnlich wie Lecture 20

Multithreading
MultithreadingMultithreading
Multithreading
sagsharma
 

Ähnlich wie Lecture 20 (20)

Slide 7 Thread-1.pptx
Slide 7 Thread-1.pptxSlide 7 Thread-1.pptx
Slide 7 Thread-1.pptx
 
Threading concepts
Threading conceptsThreading concepts
Threading concepts
 
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 in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Md09 multithreading
Md09 multithreadingMd09 multithreading
Md09 multithreading
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in java
 
Java
JavaJava
Java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Java
JavaJava
Java
 
multithreading
multithreadingmultithreading
multithreading
 
Java multithreading
Java multithreadingJava multithreading
Java multithreading
 
Unit-3 MULTITHREADING-2.pdf
Unit-3 MULTITHREADING-2.pdfUnit-3 MULTITHREADING-2.pdf
Unit-3 MULTITHREADING-2.pdf
 
Java unit 12
Java unit 12Java unit 12
Java unit 12
 

Mehr von Debasish Pratihari (19)

Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
Lecture 16
Lecture 16Lecture 16
Lecture 16
 
Lecture 14
Lecture 14Lecture 14
Lecture 14
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture25
Lecture25Lecture25
Lecture25
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Lecture 20

  • 1. Core Java Debasish Pratihari Thread  A thread is the basic unit to which the operating system allocates processor time.  Threads are useful to execute more or less independent code segments concurrently of a program.  Is knows as light-weight process.  Threads are always owned and managed by operating system.  Every program has at least one thread. User Thread  A user thread has a life-time of its own.  It is not depended on the thread that creates it.  It can continue execution after the thread that created has ended. Daemon Thread  Is a background thread that sub-ordinate to the thread that creates it  When the thread that created the daemon thread ends, the daemon thread dies with it.  A thread can be set to daemon before it starts  Threads created from daemon thread are daemon by default. Lecture/core/thread1/20 Page #1 feel the Technology…
  • 2. Core Java Debasish Pratihari Process  It has its own address space.  A process can’t access another process’s memory .  Each process provides the resources needed to execute a program.  Threads belongs to same process shares same address space.  A process has at least one thread of execution. Thread Objects:  Each thread is associated with an instance of the class Thread  There are two ways for using thread object  Directly controlling thread  Using executor Creating Thread  Provide a Runnable Object class Lakshya implements Runnable{ --}  Sub class Thread class Lakshya extends Thread{ --} Lecture/core/thread1/20 Page #2 feel the Technology…
  • 3. Core Java Debasish Pratihari Thread State:  New Born State: When we create a Thread Object then a Thread is born.  Runnable State: When we call the start( ) method on a thread then thread is in the Runnable state i.e., the threads in Runnable state are all waiting in a queue for the availability of CPU attention or their turns to come.  Running State: When a thread got the time of CPU then it starts execution for a particular interval of time (time slice) this state is called as Running state.  Blocked state: A thread is in the blocked state when it is prevented to entered into Runnable state.  Dead state: This is the end of life of a thread, when a thread completes execution comes to the dead state. Also we can dead state by calling stop( ) method. New Born Start ( ) sleep ( ) Runnable State Stop ( ) Scheduling Dead State Lecture/core/thread1/20 Running State Block State after time-slice or yield( ) Page #3 feel the Technology…
  • 4. Core Java  Debasish Pratihari A Thread enters into blocked state under the following situation.     By sleeping a thread. If a thread is waiting for I/O operation. If a thread is Interrupted. If a thread is waiting for lock available. Thread Life-Cycle 25% New Born start( ) start ( ) notify( )/ notifyAll ( ) Runnable State wait lock available I/O complete after t time Scheduling mechanism after time slice sleep( ) wait( ) Running State wait for Lock wait for I/O sleep( t ) B L O C K E D S T A T E Dead State Lecture/core/thread1/20 Page #4 feel the Technology…