Home »
Java programming language
Java Thread Class final int getPriority() method with Example
Java Thread Class final int getPriority() method: Here, we are going to learn about the final int getPriority() method of Thread class with its syntax and example.
Submitted by Preeti Jain, on July 20, 2019
Thread Class final int getPriority()
- This method is available in package java.lang.Thread.getPriority().
- This method is used to return the priority of this thread.
- This method is not static so this method is accessible with Thread class object it is not accessible with the class name.
- This method is final so we can't override this method in our program.
- The return type of this method is int so it returns the integer of this thread as a number (i.e. Priority will be in number).
- This method does not raise any exception.
- We need to notice that if we don't assign any priority explicitly the default priority of this thread is 5.
Syntax:
final int getPriority(){
}
Parameter(s):
We don't pass any object as a parameter in the method of the Thread.
Return value:
The return type of this method is int, it returns the priority of this thread as a number.
Java program to demonstrate example of getPriority() method
/* We will use Thread class methods so we are importing
the package but it is not mandate because
it is imported by default
*/
import java.lang.Thread;
class GetThreadPriority extends Thread {
// Override run() of Thread class
public void run() {
// By using getPriority() method is used to get the
// priority of this thread
System.out.println("The priority of this thread is : " + Thread.currentThread().getPriority());
}
public static void main(String[] args) {
// Creating an object of GetThreadPriority class
GetThreadPriority gt_priority = new GetThreadPriority();
// We are setting the name of the thread GetThreadPriority
gt_priority.setName("GetThreadPriority");
// Calling start() method with GetThreadPriority class
// object of Thread class
gt_priority.start();
// By using getName() method to return the name of
// this thread [GetThreadPriority ]
System.out.println("The name of this thread is " + " " + gt_priority.getName());
}
}
Output
E:\Programs>javac GetThreadPriority.java
E:\Programs>java GetThreadPriority
The name of this thread is GetThreadPriority
The priority of this thread is : 5