The time-slice scheduler controls the amount of processor time each virtual machine and application thread receives by setting priorities for them. This section describes priorities and how the time slicer assigns them.
Threads, including separate virtual machine and application threads, have 32 possible priorities, which are divided into four priority classes: idle, normal, high, and real time. Furthermore, the normal priority class is divided into foreground and background subclasses. The following table shows how priorities are divided into classes:
Class | Priorities |
Idle | 1-6, 15 (15 if the base-relative realtime thread priority is specified) |
Normal | |
Background | 1 or 5-9, 15 (1 if the base-relative idle thread priority is specified) |
Foreground | 1 or 7-11 or 15 |
High | 1 or 11-15 |
Real time | 16-31 |
Priority 0 is reserved for system use as the system idle priority. Classifying priorities helps to define dynamically variable priority ranges and establishes application guidelines to prevent monopolizing the system with simple set-priority system calls.
All 32 priorities are preemptive of priorities lower than themselves. This means that a runnable thread of one priority preempts all lower priority threads. Threads that are running at the same priority are scheduled in a round robin fashion.
All time slices are for a statistically constant period of time, called the time-slice quantum. This means that, although two time slices may have different periods, the average period of any large time slice sample remains constant.
A thread with a priority that is lower than the real-time priority class can have its priority dynamically boosted to respond more quickly to system events or to enhance overall system throughput. For example, a thread that is just becoming unblocked receives a boost in priority so that, among other threads with the same priority, it will be chosen to execute next. A dynamically boosted thread automatically loses a specified amount of boost for every time slice that it executes. This is called timed decayed boosting, and is used whenever dynamic priority boosting is indicated. Also, when the system detects that a boosted thread no longer needs its boost, the system may return the thread to its original base priority.