SlideShare a Scribd company logo
1 of 4
Download to read offline
Core Java

Debasish Pratihari

Multi-Threading :


A multithread program contains two or more
parts that can run concurrently. Each part of
such program is called a thread, and each
thread defines a separate path of execution.



Multithreading is a specialized form of
multitasking.



Multithreading enables you to write very
efficient programs that make maximum use of
the CPU, because idle time can be kept to a
minimum.

Methods of thread class :
getName()
getPriority()
getId()
getThreadGroup()
isAlive()
join()
run()
sleep()
start()

setName()
setPriority()
setDaemon()
yield ()
interrupt()
isDaemon()
isInterrupted()

Thread Priority :


Java assigns to each thread a priority that
determines how that thread should be treated with
respect to the others. Thread priorities are
integers that specify the relative priority of one
thread to another. A higher-priority thread does
not run faster than a low priority thread. Instead, a
thread priority is used to decide when to switch
from one running thread to the next. This is called
context switching. The constants to set priority
are:
MIN_PRIORITY=1
MAX_PRIORITY=10
NORM_PRIORITY=5

Lecture/core/thread2/21

Page #1

feel the Technology…
Core Java

Debasish Pratihari

Thread Synchronization :


When two or more threads need access to a
shared resources, they need some way to
ensure that the resource will be used by only
one thread at a time. The process by which this
is achieved is called synchronization.



When a thread invokes a synchronized method ,
it automatically acquires the intrinsic lock for
that method’s object and releases it when the
method return. The lock releases occurs even if
the return was caused by an un-caught
exception.

Synchronization Methods :
o Synchronized Methods
void fun(){
synchronized( expr ) {
// 'expr' must evaluate to an Object

}

}
o Synchronized Statement
public synchronized void fun() {
//method body here
}

More About Synchronize Key word:


The synchronized keyword is NOT considered
part of a method's signature.



It is not automatically inherited when
subclasses override super class methods



methods in Interfaces cannot be declared
synchronized



constructors cannot be declared synchronized
however they can contain synchronized blocks

Lecture/core/thread2/21

Page #2

feel the Technology…
Core Java

Debasish Pratihari

Thread Interrupts:


A thread can signal another thread that is should
stop executing by calling interrupt() method for that
thread object.

class MyThread extends Thread{
Thread2(){
start();
}
public void run(){
for(int i=1;i<=1000;i++){
System.out.println(i);
if(Thread.interrupted())
System.out.println("Thread Inrrupted..");
}
}

}

class ThreadTest{
public static void main(String args[]){
MyThread t= new MyThread ();
while(true){
while(!t.isInterrupted()){
t.interrupt();
System.out.println("Interrupted by
main");
}
}
}

}

Output :

Lecture/core/thread2/21

Page #3

feel the Technology…
Core Java

Debasish Pratihari

Thread Group:






Every Java thread is a member of a Thread
Group.
ThreadGroup facilitate to operate or manage
threads as group.
Java runtime system creates a Thread Group
named “main”.
If any thread is created without a thread group
specification , the runtime system put the
thread into main.
Once a thread became a member of a group it
can’t be removed from that group.

Creating a Thread Group :
25%

ThreadGroup debThreads = new ThreadGroup("debasish");

Putting Threads into ThreadGroup:
Thread debThread = new Thread(debThreads, this);

Getting a Thread’s group:
ThreadGroup group = debThread.getThreadGroup();

Example:
public class GroupTest{
public static void main(String ar[]){
ThreadGroup
group=Thread.currentThread().getThreadGroup();
System.out.println(group.getName());
System.out.println(group.activeCount());
}
}

Output :
main
1

Lecture/core/thread2/21

Page #4

feel the Technology…

More Related Content

What's hot

Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)choksheak
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaArafat Hossan
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And MultithreadingShraddha
 
Learning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and SynchronizationLearning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and Synchronizationcaswenson
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread SynchronizationBenj Del Mundo
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javajunnubabu
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAvasuraj pandey
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37myrajendra
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVAVINOTH R
 
Java Multithreading
Java MultithreadingJava Multithreading
Java MultithreadingRajkattamuri
 
Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded ApplicationsBharat17485
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkArun Mehra
 

What's hot (19)

Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
 
Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)
 
Thread model in java
Thread model in javaThread model in java
Thread model in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Learning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and SynchronizationLearning Java 3 – Threads and Synchronization
Learning Java 3 – Threads and Synchronization
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
Java thread
Java threadJava thread
Java thread
 
Thread
ThreadThread
Thread
 
multi threading
multi threadingmulti threading
multi threading
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Java Multithreading
Java MultithreadingJava Multithreading
Java Multithreading
 
javathreads
javathreadsjavathreads
javathreads
 
Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded Applications
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors Framework
 

Viewers also liked

A History Of Salento Colombia
A History Of Salento ColombiaA History Of Salento Colombia
A History Of Salento ColombiaSergio Pino
 
Dünyamizin eksen eği̇kli̇ği̇ ve sonuçlari
Dünyamizin eksen eği̇kli̇ği̇ ve sonuçlariDünyamizin eksen eği̇kli̇ği̇ ve sonuçlari
Dünyamizin eksen eği̇kli̇ği̇ ve sonuçlariEsra Öncül
 
Maximising the usage of Learning Pool's DLE forums
Maximising the usage of Learning Pool's DLE forumsMaximising the usage of Learning Pool's DLE forums
Maximising the usage of Learning Pool's DLE forumsPaul McElvaney
 
Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...
Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...
Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...Paul McElvaney
 
Cha Bar Tati - 12.05.07
Cha Bar Tati - 12.05.07Cha Bar Tati - 12.05.07
Cha Bar Tati - 12.05.07Jubrac Jacui
 
Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.
Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.
Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.Paul McElvaney
 
Workshop Summer Academy
Workshop Summer AcademyWorkshop Summer Academy
Workshop Summer AcademySjef Kerkhofs
 
Lezing Managementboek 15 feb
Lezing Managementboek 15 febLezing Managementboek 15 feb
Lezing Managementboek 15 febSjef Kerkhofs
 
Adding A Link To A Flick’R Photo
Adding A Link To A Flick’R PhotoAdding A Link To A Flick’R Photo
Adding A Link To A Flick’R PhotoLutie
 
090703 Sns Miyamura
090703 Sns Miyamura090703 Sns Miyamura
090703 Sns Miyamurayuu_2003
 
Presentatie Transmedia
Presentatie TransmediaPresentatie Transmedia
Presentatie TransmediaSjef Kerkhofs
 
Presentation1
Presentation1Presentation1
Presentation1xiammaix
 
The shifting art of animal breeding
The shifting art of animal breedingThe shifting art of animal breeding
The shifting art of animal breedingSijne Van der Beek
 

Viewers also liked (20)

A History Of Salento Colombia
A History Of Salento ColombiaA History Of Salento Colombia
A History Of Salento Colombia
 
Dünyamizin eksen eği̇kli̇ği̇ ve sonuçlari
Dünyamizin eksen eği̇kli̇ği̇ ve sonuçlariDünyamizin eksen eği̇kli̇ği̇ ve sonuçlari
Dünyamizin eksen eği̇kli̇ği̇ ve sonuçlari
 
My Learning Pool
My Learning PoolMy Learning Pool
My Learning Pool
 
The Big Bang of the Internet of Things
The Big Bang of the Internet of ThingsThe Big Bang of the Internet of Things
The Big Bang of the Internet of Things
 
Mobile Tv
Mobile TvMobile Tv
Mobile Tv
 
Maximising the usage of Learning Pool's DLE forums
Maximising the usage of Learning Pool's DLE forumsMaximising the usage of Learning Pool's DLE forums
Maximising the usage of Learning Pool's DLE forums
 
Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...
Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...
Learning Pool: Yorkshire & Humber Learning Platform Adult Social Care: E-lear...
 
Cha Bar Tati - 12.05.07
Cha Bar Tati - 12.05.07Cha Bar Tati - 12.05.07
Cha Bar Tati - 12.05.07
 
Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.
Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.
Learning Pool's Mark Lynch and Kevin Gallagher on 'Next Generation DLE'.
 
I Love To Travel. I Travel To Live.
I Love To Travel. I Travel To Live.I Love To Travel. I Travel To Live.
I Love To Travel. I Travel To Live.
 
Workshop Summer Academy
Workshop Summer AcademyWorkshop Summer Academy
Workshop Summer Academy
 
Tnt 20 jan pdf
Tnt 20 jan pdfTnt 20 jan pdf
Tnt 20 jan pdf
 
Talking In Class
Talking In ClassTalking In Class
Talking In Class
 
Lezing Managementboek 15 feb
Lezing Managementboek 15 febLezing Managementboek 15 feb
Lezing Managementboek 15 feb
 
Adding A Link To A Flick’R Photo
Adding A Link To A Flick’R PhotoAdding A Link To A Flick’R Photo
Adding A Link To A Flick’R Photo
 
090703 Sns Miyamura
090703 Sns Miyamura090703 Sns Miyamura
090703 Sns Miyamura
 
Presentatie Transmedia
Presentatie TransmediaPresentatie Transmedia
Presentatie Transmedia
 
Presentation1
Presentation1Presentation1
Presentation1
 
The shifting art of animal breeding
The shifting art of animal breedingThe shifting art of animal breeding
The shifting art of animal breeding
 
Presentatie ANWB
Presentatie  ANWBPresentatie  ANWB
Presentatie ANWB
 

Similar to Lecture 21 (20)

Multi-threaded Programming in JAVA
Multi-threaded Programming in JAVAMulti-threaded Programming in JAVA
Multi-threaded Programming in JAVA
 
Multithreading
MultithreadingMultithreading
Multithreading
 
advanced java ppt
advanced java pptadvanced java ppt
advanced java ppt
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Threadnotes
ThreadnotesThreadnotes
Threadnotes
 
Java unit 12
Java unit 12Java unit 12
Java unit 12
 
Threads
ThreadsThreads
Threads
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Threads
ThreadsThreads
Threads
 
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java - Concurrent programming - Thread's basics
Java - Concurrent programming - Thread's basicsJava - Concurrent programming - Thread's basics
Java - Concurrent programming - Thread's basics
 
unit-3java.pptx
unit-3java.pptxunit-3java.pptx
unit-3java.pptx
 
Understanding Threads in operating system
Understanding Threads in operating systemUnderstanding Threads in operating system
Understanding Threads in operating system
 
9.multi-threading latest(MB).ppt .
9.multi-threading latest(MB).ppt            .9.multi-threading latest(MB).ppt            .
9.multi-threading latest(MB).ppt .
 
Md09 multithreading
Md09 multithreadingMd09 multithreading
Md09 multithreading
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Slide 7 Thread-1.pptx
Slide 7 Thread-1.pptxSlide 7 Thread-1.pptx
Slide 7 Thread-1.pptx
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 

More from Debasish Pratihari (20)

Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Lecture 20
Lecture 20Lecture 20
Lecture 20
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
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
 

Recently uploaded

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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 WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
+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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Lecture 21

  • 1. Core Java Debasish Pratihari Multi-Threading :  A multithread program contains two or more parts that can run concurrently. Each part of such program is called a thread, and each thread defines a separate path of execution.  Multithreading is a specialized form of multitasking.  Multithreading enables you to write very efficient programs that make maximum use of the CPU, because idle time can be kept to a minimum. Methods of thread class : getName() getPriority() getId() getThreadGroup() isAlive() join() run() sleep() start() setName() setPriority() setDaemon() yield () interrupt() isDaemon() isInterrupted() Thread Priority :  Java assigns to each thread a priority that determines how that thread should be treated with respect to the others. Thread priorities are integers that specify the relative priority of one thread to another. A higher-priority thread does not run faster than a low priority thread. Instead, a thread priority is used to decide when to switch from one running thread to the next. This is called context switching. The constants to set priority are: MIN_PRIORITY=1 MAX_PRIORITY=10 NORM_PRIORITY=5 Lecture/core/thread2/21 Page #1 feel the Technology…
  • 2. Core Java Debasish Pratihari Thread Synchronization :  When two or more threads need access to a shared resources, they need some way to ensure that the resource will be used by only one thread at a time. The process by which this is achieved is called synchronization.  When a thread invokes a synchronized method , it automatically acquires the intrinsic lock for that method’s object and releases it when the method return. The lock releases occurs even if the return was caused by an un-caught exception. Synchronization Methods : o Synchronized Methods void fun(){ synchronized( expr ) { // 'expr' must evaluate to an Object } } o Synchronized Statement public synchronized void fun() { //method body here } More About Synchronize Key word:  The synchronized keyword is NOT considered part of a method's signature.  It is not automatically inherited when subclasses override super class methods  methods in Interfaces cannot be declared synchronized  constructors cannot be declared synchronized however they can contain synchronized blocks Lecture/core/thread2/21 Page #2 feel the Technology…
  • 3. Core Java Debasish Pratihari Thread Interrupts:  A thread can signal another thread that is should stop executing by calling interrupt() method for that thread object. class MyThread extends Thread{ Thread2(){ start(); } public void run(){ for(int i=1;i<=1000;i++){ System.out.println(i); if(Thread.interrupted()) System.out.println("Thread Inrrupted.."); } } } class ThreadTest{ public static void main(String args[]){ MyThread t= new MyThread (); while(true){ while(!t.isInterrupted()){ t.interrupt(); System.out.println("Interrupted by main"); } } } } Output : Lecture/core/thread2/21 Page #3 feel the Technology…
  • 4. Core Java Debasish Pratihari Thread Group:      Every Java thread is a member of a Thread Group. ThreadGroup facilitate to operate or manage threads as group. Java runtime system creates a Thread Group named “main”. If any thread is created without a thread group specification , the runtime system put the thread into main. Once a thread became a member of a group it can’t be removed from that group. Creating a Thread Group : 25% ThreadGroup debThreads = new ThreadGroup("debasish"); Putting Threads into ThreadGroup: Thread debThread = new Thread(debThreads, this); Getting a Thread’s group: ThreadGroup group = debThread.getThreadGroup(); Example: public class GroupTest{ public static void main(String ar[]){ ThreadGroup group=Thread.currentThread().getThreadGroup(); System.out.println(group.getName()); System.out.println(group.activeCount()); } } Output : main 1 Lecture/core/thread2/21 Page #4 feel the Technology…