7.6. Thread Priorities

As mentioned at the beginning of the chapter, multi-threading is achieved by rapidly switching between one thread and another to simulate concurrent execution of code. Unless there are multiple CPUs, the operating system will switch between one thread and another based on an arbitrary algorithm over which individual threads have no control. Thus, it is impossible to predict the order in which threads will be executed, or when (if at all) a thread will be scheduled. The best that can be done is to suggest the relative priority of threads, which gives the operating system an indication of which threads are more important (and should be scheduled more frequently, or for a longer duration).

7.6.1. Assigning a Thread Priority ...

Get Java™ Network Programming and Distributed Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.