主线程优先级的值是多少?

所有线程都有自己的优先级,那么主线程的整数值是多少?

此代码显示主线程的优先级:

public class Main { public static void main( String [] args ) { System.out.println( Thread.currentThread().getPriority() ); } } 

输出和问题的答案是5

如果您仍有任何疑问,请查看JDK的API文档:

来自http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#NORM_PRIORITY :

NORM_PRIORITY

public static final int NORM_PRIORITY

分配给线程的默认优先级。

来自http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.lang.Thread.NORM_PRIORITY :

static final int NORM_PRIORITY 5

默认情况下线程值是6 …….