What is Thread priority?

Threads always run with some priority, usually represented as a number between 1
and 10.
In most JVMs, however, the scheduler does use thread priorities in one important
way: If a thread enters the runnable state, and it has a higher priority than any of
the threads in the pool and a higher priority than the currently running thread,
the lower-priority running thread usually will be bumped back to runnable and the
highest-priority thread will be chosen to run. In other words, at any given time the
currently running thread usually will not have a priority that is lower than any of
the threads in the pool. In most cases, the running thread will be of equal or greater
priority than the highest priority threads in the pool.
Setting a Thread's Priority
FooRunnable r = new FooRunnable();
Thread t = new Thread(r);
A thread’s default prority is 5.
Thread class has the three following
constants (static final variables) that define the range of thread priorities:
Thread.MAX_PRIORITY (10)
If priority not explicitly set, a thread's priority will have the same priority as the
priority of the thread that created it.

No comments:

Post a Comment