- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Minimum and Maximum Priority Threads in Java
The thread priority determines when the processor is provided to the thread as well as other resources. It can be changed using the method setPriority() of class Thread.
There are three static variables for thread priority in Java i.e. MIN_PRIORITY, MAX_PRIORITY and NORM_PRIORITY. The values of these variables are 1, 10 and 5 respectively.
A program that demonstrates this is given as follows:
Example
public class ThreadDemo extends Thread { public void run() { System.out.println("Running..."); } public static void main(String[] args) { ThreadDemo thread1 = new ThreadDemo(); ThreadDemo thread2 = new ThreadDemo(); System.out.println("Default thread priority of Thread 1: " + thread1.getPriority()); System.out.println("Default thread priority of Thread 2: " + thread2.getPriority()); thread1.setPriority(MAX_PRIORITY); thread2.setPriority(MIN_PRIORITY); System.out.println("
The maximum thread priority of Thread 1 is: " + thread1.getPriority()); System.out.println("The minimum thread priority of Thread 2 is: " + thread2.getPriority()); System.out.println("
" + Thread.currentThread().getName()); System.out.println("Default thread priority of Main Thread: " + Thread.currentThread().getPriority()); Thread.currentThread().setPriority(MAX_PRIORITY); System.out.println("The maximum thread priority of Main Thread is: " + Thread.currentThread().getPriority()); } }
Output
Default thread priority of Thread 1: 5 Default thread priority of Thread 2: 5 The maximum thread priority of Thread 1 is: 10 The minimum thread priority of Thread 2 is: 1 main Default thread priority of Main Thread: 5 The maximum thread priority of Main Thread is: 10
- Related Articles
- Difference Between Daemon Threads and User Threads In Java
- Joining Threads in Java
- Killing threads in Java
- Display Minimum and Maximum values of datatype int in Java
- Java Program to Set Minimum and Maximum Heap Size
- How to read Maximum and Minimum temperature in Six's Maximum and Minimum Thermometer?
- Java Program to Get Minimum and Maximum From a List
- Display the minimum and maximum value of primitive data types in Java
- Java program to find Maximum and minimum element’s position in a list
- Change Thread Priority in Java
- Java Thread Priority in Multithreading
- What Is Maximum and Minimum ?
- Get maximum and minimum value in MongoDB?
- Maximum and Minimum Product Subsets in C++
- Getting Minimum and Maximum Value in MySQL

Advertisements