Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Single-processor computers use a special scheduling algorithm that allocates processor time slices to the running threads based on their priorities. If Thread1 is using the processor and the higher-priority Thread2 wakes up, Thread1 is pushed aside and Thread2 gets the CPU. It is said that Thread2 preempts Thread1.
The class Thread has a method, setPriority(), that allows you to control its priority. There are 10 different priorities, which are final integer variables defined in the class Thread. Some of them are named constants MIN_PRIORITY, NORM_PRIORITY, and MAX_PRIORITY. Here's an example of their usage: