Java Api之线程的优先级

/ JAVA API / 没有评论 / 460浏览

Java Api之线程的优先级



public class PriorityDemo {
  public static void main(String[] args) {
    Thread min = new Thread() {
	public void run() {
	  for (int i = 0; i < 1000; i++) {
	    System.out.println("min");
			}
		}
	};
		
    Thread nor = new Thread() {
      public void run() {
        for (int i = 0; i < 1000; i++) {
	   System.out.println("nor");
			}
		}
	};
		
    Thread max = new Thread() {
	public void run() {
	  for (int i = 0; i < 1000; i++) {
	    System.out.println("max");		
			}
		}
	};
		
    //线程的最大优先级
    max.setPriority(Thread.MAX_PRIORITY);
    //线程的最小优先级
    min.setPriority(Thread.MIN_PRIORITY);
		
    min.start();
    nor.start();
    max.start();
		
	}
}