Java Data Type Tutorial - Java Thread.getPriority()








Syntax

Thread.getPriority() has the following syntax.

public final int getPriority()

Example

In the following code shows how to use Thread.getPriority() method.

/*from   w  ww  . j  a  va  2  s . c om*/
class ThreadDemo extends Thread{
  public void run() {
    System.out.println("Thread priority = " + getPriority());
  }
}

public class Main {
  public static void main(String args[]) {
    Thread t = new Thread(new ThreadDemo(), "java2s.com thread");
    t.setPriority(1);

    System.out.println("thread  = " + t);

    t.start();
  }
}

The code above generates the following result.