Java Data Type Tutorial - Java Thread.setPriority(int newPriority)








Syntax

Thread.setPriority(int newPriority) has the following syntax.

public final void setPriority(int newPriority)

Example

In the following code shows how to use Thread.setPriority(int newPriority) method.

// www. j a  va2s.  c  o m

public class Main {

  public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(1);

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

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
  }
}

The code above generates the following result.