Skip to Main Content
Java Threads, 3rd Edition
book

Java Threads, 3rd Edition

by Scott Oaks, Henry Wong
September 2004
Intermediate to advanced content levelIntermediate to advanced
362 pages
11h 24m
English
O'Reilly Media, Inc.
Content preview from Java Threads, 3rd Edition

Chapter 9. Thread Scheduling

The term “thread scheduling” covers a variety of topics. This chapter examines one of those topics, which is how a computer selects particular threads to run. The information in this chapter provides a basic understanding of when threads run and how computers handle multiple threads. There’s little programming in this chapter, but the information we present is an important foundation for other topics of thread scheduling. In particular, the next few chapters discuss task scheduling and thread pools, which are the programmatic techniques you use to manage large numbers of threads and jobs.

The key to understanding Java thread scheduling is to realize that a CPU is a scarce resource. When two or more threads want to run on a single-processor machine, they end up competing for the CPU, and it’s up to someone—either the programmer, the Java virtual machine, or the operating system—to make sure that the CPU is shared among these threads. The same is true whenever a program has more threads than the machine hosting the program has CPUs. The essence of this chapter is to understand how CPUs are shared among threads that want to access them.

In earlier examples, we didn’t concern ourselves with this topic because, in those cases, the details of thread scheduling weren’t important to us. This was because the threads we were concerned with didn’t normally compete for a CPU: they had specific tasks to do, but the threads themselves were usually short-lived or only ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Performance: The Definitive Guide

Java Performance: The Definitive Guide

Scott Oaks
Java Concurrency, 2/e

Java Concurrency, 2/e

Douglas Schmidt
Java Swing, 2nd Edition

Java Swing, 2nd Edition

Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole

Publisher Resources

ISBN: 0596007825Supplemental ContentErrata Page