Monday, March 2, 2015

JAVA THREAD PRIORITY

A thread gets a default priority that is the priority of the thread of execution that creates it.

public class MainThread {
public static void main (String [] box) {
Thread th = new Thread();
}
}
the thread referenced by th will have the same priority as the main thread.

One can also set priority using the .setPriority() method.

The thread priority value must be in range 1 to 10.

Thread priority range is also depends on the JVM some JVM takes only values between 1 to 5.

JVM never changes the thread priority.

Any thread's default priority is 5.

There are three constants in the Thread class for the thread priority.
Thread.MIN_PRIORITY (1)
Thread.NORM_PRIORITY (5)
Thread.MAX_PRIORITY (10)

If user sets  1o 10 priorities for ten different threads and if the JVM doesnt support 1 to 10 priorities but 
it support 1 to 5 priority then some of the thread among the 10 will have duplicate priorities.


No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...