all threads have its priority,so what is the integer value for main thread?
+6
A:
Let's see:
cat Main.java
public class Main {
public static void main( String [] args ) {
System.out.println( Thread.currentThread().getPriority() );
}
}
javac Main.java
java Main
5
The answer is 5
OscarRyz
2009-08-13 03:07:37
Isn't it 5 for every thread by default?
Adeel Ansari
2009-08-13 03:21:36
Not *all* threads will start with NORM_PRIORITY. Per Thread JavaDocs - "When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread." I thought I should clarify that.
Jack Leow
2009-08-13 11:24:25
+2
A:
If you still have any doubts, have a look at the JDK's API docs:
From http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#NORM_PRIORITY:
NORM_PRIORITY
public static final int NORM_PRIORITY
The default priority that is assigned to a thread.
From http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.lang.Thread.NORM_PRIORITY:
static final int NORM_PRIORITY 5
Jack Leow
2009-08-13 03:40:26