There is a lot of good documentation on this topic. One of these is this .
When a Java thread is created, it inherits its priority from the thread that created it. You can also change the priority of a stream at any time after creating it using the setPriority () method. Thread priorities are integers from MIN_PRIORITY and MAX_PRIORITY (constants defined in the Thread class). The higher the integer, the higher the priority. At any given time, when multiple threads are ready to be executed, the runtime system selects the “Runnable” thread with the highest priority for execution. Only when this thread stops, issues, or becomes "Not Runnable", for some reason, a downstream thread with a lower priority will start. If two threads of the same priority are waiting for the CPU, the scheduler selects one of them for a cyclic start. The selected thread will work until one of the following conditions is met:
- A thread with a higher priority becomes "Runnable".
- It returns or its run () method exits.
- On systems that support time reference, it has expired.
At any given time, the thread with the highest priority is executed. However, this is not guaranteed. The thread scheduler can choose to start a thread with a lower priority to avoid starvation. For this reason, use priority to influence planning policies for effectiveness. Do not rely on thread priority for the correctness of the algorithm.
source share