Every thread has a priority, which is an integer from 1 to 10 : Thread Priority « Thread « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Thread » Thread Priority 
7.3.3.Every thread has a priority, which is an integer from 1 to 10
class DownCounter implements Runnable {
  public void run() {
    for (int i = 10; i >= 1; i--) {
      System.out.println("Counting Down: " + i);
    }
  }
}

public class MainClass {
  public static void main(String[] argv) {
    DownCounter dc = new DownCounter();
    Thread t = new Thread(dc);
    t.start();

    int oldPriority = t.getPriority();
    int newPriority = Math.min(oldPriority + 1, Thread.MAX_PRIORITY);
    t.setPriority(newPriority);

  }
}
Counting Down: 10
Counting Down: 9
Counting Down: 8
Counting Down: 7
Counting Down: 6
Counting Down: 5
Counting Down: 4
Counting Down: 3
Counting Down: 2
Counting Down: 1
7.3.Thread Priority
7.3.1.Thread Priorities
7.3.2.Thread class defines constants for MIN_PRIORITY (which is 1) and NORM_PRIORITY (which is 5).
7.3.3.Every thread has a priority, which is an integer from 1 to 10
7.3.4.The default priority is 5
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.