•The priority of the thread decides which thread will get the most time of the CPU for execution.
•Generally a higher priority thread gets more share of the CPU than the lower priority thread.
•“Thread” class provides two methods for dealing with priorities:
1) setPriority() – Used to set the priority of a thread.
final void setPriority(int level)
2) getPriority() – Used to get the priority of a thread.
final int getPriority()
•There are 10 priority levels in a thread starting from 1 and ending with 10.
•1 is the least priority level.
•10 is the highest priority level.
•5 is the normal priority level.
•By default every thread starts at normal priority level 5.
•Instead of directly using numbers we can use names to assign the priority to a thread:
MIN_PRIORITY denotes 1
MAX_PRIORITY denotes 10
NORM_PRIORITY denotes 5
No comments:
Post a Comment