SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Thread Priority in Java
CPU
Thread
with
priority 2
Thread
with
priority 5
Thread
with
priority 9
Thread
with
priority 7
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
Thread Priority
Thread Priority is a number assigned to every thread, on which thread
scheduler takes the decision, which thread executes first amongst multiple
threads.
Whenever the thread-scheduler pick a new thread, from the ready thread, it
picks the highest-priority thread.
We can set the priority of each thread .
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
Java Thread Priority
In Java each thread inherits its priority by its
parent thread.
Every thread have priority by default i.e. 5.
We can increase or decrease the thread priority by
built-in method of Thread class of Java.
We can set the priority of thread from 1 to 10.
Where 10 is the highest priority and 1 is the least
priority.
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
Method for the Priority
‱ getPriority()
– This method is used to know the priority of a
thread.
e.g.
System.out.println(threadName.getPriority())
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
Method for the Priority
‱ setPriority()
– It is used to set the priority from 1 to 10 to a
particular thread.
– e.g.
threadName.setPriority(4);
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
Java Constant for Priority
Following are the in built constant for priorities:
Constant Priority
‱ MAX_PRIORITY 10
‱ MIN_PRIORITY 1
‱ NORM_PRIORITY 5
e.g. for setting the priority using constant:
threadName.setPriority(Thread.MAX_PRIORITY);
threadName.setPriority(Thread.MIN_PRIORITY);
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
Limitation of Java Thread Priority
‱ Rule of thread priority is system dependent (OS)
‱ Some OS have very few priority level than Java i.e.
10. In this case there is no use to set the high
priority upto 10.
‱ When there is more than 1 thread of same
priority then scheduler of OS pick anyone as per
the scheduling algorithm.
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
public class CheckRunnable {
public static void main(String args[])
{
AThread1 obj1 = new AThread1();
BThread1 obj2 = new BThread1();
CThread1 obj3 = new CThread1();
Thread.currentThread().setPriority(8);
Thread Athread = new Thread(obj1);
Thread Bthread = new Thread(obj2);
Thread Cthread = new Thread(obj3);
System.out.println(Athread.getPriority());
System.out.println(Bthread.getPriority());
System.out.println(Cthread.getPriority());
System.out.println(Thread.currentThread().getPriority());
Bthread.setPriority(Thread.MIN_PRIORITY);
System.out.println(Bthread.getPriority());
Athread.start();
Bthread.start();
Cthread.start();
}
}
class AThread1 implements Runnable
{
public void run()
{
for(int i = 1;i<=5;i++)
{
System.out.println("Athread" + " " + i);
try {Thread.sleep(500);
}catch(Exception e)
{}}}}
class BThread1 implements Runnable
{
public void run()
{
System.out.println("BThread");
}}
class CThread1 implements Runnable
{
public void run()
{
System.out.println("CThread");
}
}
Program to set priority of current thread/parent thread and use of constant
Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s

Weitere Àhnliche Inhalte

Was ist angesagt?

Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 
trigger dbms
trigger dbmstrigger dbms
trigger dbmskuldeep100
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVAVINOTH R
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in JavaNaz Abdalla
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control TechniquesRaj vardhan
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database TriggerEryk Budi Pratama
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Preventionprachi mewara
 
Triggers in SQL | Edureka
Triggers in SQL | EdurekaTriggers in SQL | Edureka
Triggers in SQL | EdurekaEdureka!
 
OOP java
OOP javaOOP java
OOP javaxball977
 

Was ist angesagt? (20)

Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Java swing
Java swingJava swing
Java swing
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Triggers
TriggersTriggers
Triggers
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control Techniques
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Java notes
Java notesJava notes
Java notes
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
Thread priorities
Thread prioritiesThread priorities
Thread priorities
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Triggers in SQL | Edureka
Triggers in SQL | EdurekaTriggers in SQL | Edureka
Triggers in SQL | Edureka
 
Python libraries
Python librariesPython libraries
Python libraries
 
OOP java
OOP javaOOP java
OOP java
 

Ähnlich wie Java Thread Priority - Set, Get Priority & Constants

Thread priorities35
Thread priorities35Thread priorities35
Thread priorities35myrajendra
 
Java-Threads And Concurrency Presentation. 2024
Java-Threads And Concurrency Presentation. 2024Java-Threads And Concurrency Presentation. 2024
Java-Threads And Concurrency Presentation. 2024nehakumari0xf
 
Java Threads And Concurrency Presentation. 2024
Java Threads And Concurrency Presentation. 2024Java Threads And Concurrency Presentation. 2024
Java Threads And Concurrency Presentation. 2024kashyapneha2809
 
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
 
PROGRAMMING IN JAVA-unit 3-part II
PROGRAMMING IN JAVA-unit 3-part IIPROGRAMMING IN JAVA-unit 3-part II
PROGRAMMING IN JAVA-unit 3-part IISivaSankari36
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsMaarten Smeets
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingBadar Waseer
 
Threads in java, Multitasking and Multithreading
Threads in java, Multitasking and MultithreadingThreads in java, Multitasking and Multithreading
Threads in java, Multitasking and Multithreadingssusere538f7
 
econtent thread in java.pptx
econtent thread in java.pptxecontent thread in java.pptx
econtent thread in java.pptxramyan49
 
Slide 7 Thread-1.pptx
Slide 7 Thread-1.pptxSlide 7 Thread-1.pptx
Slide 7 Thread-1.pptxajmalhamidi1380
 
7. Multithreading
7. Multithreading7. Multithreading
7. MultithreadingNilesh Dalvi
 
TDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecer
TDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecerTDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecer
TDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecerStefan Teixeira
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptxTREXSHyNE
 
Threading concepts
Threading conceptsThreading concepts
Threading conceptsRaheemaparveen
 

Ähnlich wie Java Thread Priority - Set, Get Priority & Constants (20)

Thread priorities35
Thread priorities35Thread priorities35
Thread priorities35
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java threading
Java threadingJava threading
Java threading
 
Java-Threads And Concurrency Presentation. 2024
Java-Threads And Concurrency Presentation. 2024Java-Threads And Concurrency Presentation. 2024
Java-Threads And Concurrency Presentation. 2024
 
Java Threads And Concurrency Presentation. 2024
Java Threads And Concurrency Presentation. 2024Java Threads And Concurrency Presentation. 2024
Java Threads And Concurrency Presentation. 2024
 
Java threads
Java threadsJava threads
Java threads
 
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
 
PROGRAMMING IN JAVA-unit 3-part II
PROGRAMMING IN JAVA-unit 3-part IIPROGRAMMING IN JAVA-unit 3-part II
PROGRAMMING IN JAVA-unit 3-part II
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck Threads
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented Programming
 
Threads in java, Multitasking and Multithreading
Threads in java, Multitasking and MultithreadingThreads in java, Multitasking and Multithreading
Threads in java, Multitasking and Multithreading
 
econtent thread in java.pptx
econtent thread in java.pptxecontent thread in java.pptx
econtent thread in java.pptx
 
Slide 7 Thread-1.pptx
Slide 7 Thread-1.pptxSlide 7 Thread-1.pptx
Slide 7 Thread-1.pptx
 
7. Multithreading
7. Multithreading7. Multithreading
7. Multithreading
 
TDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecer
TDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecerTDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecer
TDC 2016 SP - 5 libs de teste JavaScript que vocĂȘ deveria conhecer
 
Threads
ThreadsThreads
Threads
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptx
 
Threading concepts
Threading conceptsThreading concepts
Threading concepts
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Threads
ThreadsThreads
Threads
 

KĂŒrzlich hochgeladen

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)lakshayb543
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

KĂŒrzlich hochgeladen (20)

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 

Java Thread Priority - Set, Get Priority & Constants

  • 1. Thread Priority in Java CPU Thread with priority 2 Thread with priority 5 Thread with priority 9 Thread with priority 7 Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
  • 2. Thread Priority Thread Priority is a number assigned to every thread, on which thread scheduler takes the decision, which thread executes first amongst multiple threads. Whenever the thread-scheduler pick a new thread, from the ready thread, it picks the highest-priority thread. We can set the priority of each thread . Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
  • 3. Java Thread Priority In Java each thread inherits its priority by its parent thread. Every thread have priority by default i.e. 5. We can increase or decrease the thread priority by built-in method of Thread class of Java. We can set the priority of thread from 1 to 10. Where 10 is the highest priority and 1 is the least priority. Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
  • 4. Method for the Priority ‱ getPriority() – This method is used to know the priority of a thread. e.g. System.out.println(threadName.getPriority()) Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
  • 5. Method for the Priority ‱ setPriority() – It is used to set the priority from 1 to 10 to a particular thread. – e.g. threadName.setPriority(4); Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
  • 6. Java Constant for Priority Following are the in built constant for priorities: Constant Priority ‱ MAX_PRIORITY 10 ‱ MIN_PRIORITY 1 ‱ NORM_PRIORITY 5 e.g. for setting the priority using constant: threadName.setPriority(Thread.MAX_PRIORITY); threadName.setPriority(Thread.MIN_PRIORITY); Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
  • 7. Limitation of Java Thread Priority ‱ Rule of thread priority is system dependent (OS) ‱ Some OS have very few priority level than Java i.e. 10. In this case there is no use to set the high priority upto 10. ‱ When there is more than 1 thread of same priority then scheduler of OS pick anyone as per the scheduling algorithm. Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s
  • 8. public class CheckRunnable { public static void main(String args[]) { AThread1 obj1 = new AThread1(); BThread1 obj2 = new BThread1(); CThread1 obj3 = new CThread1(); Thread.currentThread().setPriority(8); Thread Athread = new Thread(obj1); Thread Bthread = new Thread(obj2); Thread Cthread = new Thread(obj3); System.out.println(Athread.getPriority()); System.out.println(Bthread.getPriority()); System.out.println(Cthread.getPriority()); System.out.println(Thread.currentThread().getPriority()); Bthread.setPriority(Thread.MIN_PRIORITY); System.out.println(Bthread.getPriority()); Athread.start(); Bthread.start(); Cthread.start(); } } class AThread1 implements Runnable { public void run() { for(int i = 1;i<=5;i++) { System.out.println("Athread" + " " + i); try {Thread.sleep(500); }catch(Exception e) {}}}} class BThread1 implements Runnable { public void run() { System.out.println("BThread"); }} class CThread1 implements Runnable { public void run() { System.out.println("CThread"); } } Program to set priority of current thread/parent thread and use of constant Video link for this topic : https://www.youtube.com/watch?v=xopkQL5tpb4&t=693s