Java ThreadGroup .setMaxPriority (int pri)

Syntax

ThreadGroup.setMaxPriority(int pri) has the following syntax.

public final void setMaxPriority(int pri)

Example

In the following code shows how to use ThreadGroup.setMaxPriority(int pri) method.


public class Main {
  public static void main(String[] args) {
    new ThreadGroupDemo();
  }//from   w  w  w  .  j a v a  2  s . c o  m
}
class ThreadGroupDemo implements Runnable {
  public ThreadGroupDemo() {

    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");
    pGroup.setMaxPriority(Thread.MAX_PRIORITY - 2);

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");
    cGroup.setMaxPriority(Thread.NORM_PRIORITY);

    Thread t1 = new Thread(pGroup, this);
    t1.setPriority(Thread.MAX_PRIORITY);
    System.out.println("Starting " + t1.getName());
    t1.start();

    Thread t2 = new Thread(cGroup, this);
    t1.setPriority(Thread.MAX_PRIORITY);
    System.out.println("Starting " + t2.getName());
    t2.start();

    System.out.println("Active threads in \"" + pGroup.getName() + "\" = "
        + pGroup.activeCount());

  }

  public void run() {
    System.out.println(Thread.currentThread().getName() + " [priority = "
        + Thread.currentThread().getPriority() + "] finished executing.");
  }
}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable