views:

363

answers:

3

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
Isn't it 5 for every thread by default?
Adeel Ansari
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
+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
A: 

idi gauranty ga 5 vastadi

ravi