Priority
- The JVM scheduler is a fixed priority scheduler.
- Every thread has a priority number. Bigger is better.
- The scheduler chooses the runnable thread with the highest priority
for execution. When it stops, yields, or becomes not runnable
then a lower priority thread starts executing.
- If two threads of the same priority are waiting the
scheduler chooses one of them to run in a round-robin
fashion.
- A thread will run until:
- A higher priority thread becomes runnable, i.e., its preemptive.
- It
yield
s, or its run
method exits.
- On systems that support time-slicing, its time allotment
has expired.
- The scheduler does violate priority in order to avoid
starvation.
- On a system without time-slicing, a selfish thread will only
stop for a higher-priority thread (an equal-priority thread
might have to wait a long time.)
- On systems with time-slicing (Unix, NT, W95) same-priority
threads are interleaved.
- Remember: even if you have multiple threads, you
still only have one CPU. Be nice!
José M. Vidal
.
6 of 8