SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)UC San Diego
 
Thread model of java
Thread model of javaThread model of java
Thread model of javamyrajendra
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in javaHrithikShinde
 
Operating System Lab Manual
Operating System Lab ManualOperating System Lab Manual
Operating System Lab ManualBilal Mirza
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...whileJayfee Ramos
 
Introduction to method overloading &amp; method overriding in java hdm
Introduction to method overloading &amp; method overriding  in java  hdmIntroduction to method overloading &amp; method overriding  in java  hdm
Introduction to method overloading &amp; method overriding in java hdmHarshal Misalkar
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEdureka!
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVASAGARDAVE29
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cyclemyrajendra
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 

What's hot (20)

Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Tcp/ip server sockets
Tcp/ip server socketsTcp/ip server sockets
Tcp/ip server sockets
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
Thread model of java
Thread model of javaThread model of java
Thread model of java
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
 
Operating System Lab Manual
Operating System Lab ManualOperating System Lab Manual
Operating System Lab Manual
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Java Beans
Java BeansJava Beans
Java Beans
 
Introduction to method overloading &amp; method overriding in java hdm
Introduction to method overloading &amp; method overriding  in java  hdmIntroduction to method overloading &amp; method overriding  in java  hdm
Introduction to method overloading &amp; method overriding in java hdm
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 

Similar to 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
 
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
 

Similar to 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-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
 
java threads
java threadsjava threads
java threads
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
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
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
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🔝
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
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
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 

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