Thread priority information : Thread Attributes « Threads « Java






Thread priority information

Thread priority information
 

public class GetPriority extends Object {
  private static Runnable makeRunnable() {
    Runnable r = new Runnable() {
      public void run() {
        for (int i = 0; i < 5; i++) {
          Thread t = Thread.currentThread();
          System.out.println("in run() - priority=" + t.getPriority()
              + ", name=" + t.getName());

          try {
            Thread.sleep(2000);
          } catch (InterruptedException x) {
            // ignore
          }
        }
      }
    };

    return r;
  }

  public static void main(String[] args) {
    System.out.println("in main() - Thread.currentThread().getPriority()="
        + Thread.currentThread().getPriority());

    System.out.println("in main() - Thread.currentThread().getName()="
        + Thread.currentThread().getName());

    Thread threadA = new Thread(makeRunnable(), "threadA");
    threadA.start();

    try {
      Thread.sleep(3000);
    } catch (InterruptedException x) {
    }

    System.out.println("in main() - threadA.getPriority()="
        + threadA.getPriority());
  }
}
           
         
  








Related examples in the same category

1.Thread nameThread name
2.Get Thread nameGet Thread name
3.Thread PriorityThread Priority
4.Set Thread PrioritySet Thread Priority
5.Thread Interrupt when calculating PiThread Interrupt when calculating Pi
6.Thread pending and interruptThread pending and interrupt
7.Thread interrupt resetThread interrupt reset
8.Thread interrupt checkThread interrupt check
9.Thread general interruptThread general interrupt
10.Thread IDThread ID
11.ThreadGroup EnumerateThreadGroup Enumerate
12.Utilities to manage thread ids