Summary

We’ve shown four scheduling techniques in the chapter. The most useful of these is the notion of thread pools: a set of threads that sit idle until work is available for them. A thread pool is very useful in limiting the number of threads that are active within the virtual machine while making the best use of the host machine’s CPU resources.

We’ve also shown two techniques that can be used to perform (or limit) round-robin scheduling. Neither of these techniques is completely satisfactory: the SimpleScheduler is not guaranteed to work on all platforms, even though it works on the vast majority of them, and the CPUScheduler may show some anomalous behavior when threads under its control block. Nonetheless, for CPU-intensive threads, these techniques are very useful when you need to influence the scheduling behavior that the Java virtual machine and its host operating system provide for you.

Finally, we’ve shown how to perform batch-oriented job scheduling without requiring multiple timer threads for each job. While this is a useful mechanism in its own right, it also shows how many of the other techniques that we’ve already developed can be applied to writing thread utilities.

Get Java Threads, Second Edition 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.