Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Java Threads, 3rd Edition
A Note Regarding Supplemental Files
Preface
Who Should Read This Book?
Versions Used in This Book
What’s New in This Edition?
Organization of This Book
Conventions Used in This Book
Code Examples
How to Contact Us
Safari Enabled
Acknowledgments
1. Introduction to Threads
1.1. Java Terms
1.1.1. Java Versions, Tools, and Code
1.2. About the Examples
1.2.1. Compiling and Running the Examples
1.3. Why Threads?
1.3.1. Nonblocking I/O
1.3.2. Alarms and Timers
1.3.3. Independent Tasks
1.3.4. Parallelizable Algorithms
1.4. Summary
2. Thread Creation and Management
2.1. What Is a Thread?
2.2. Creating a Thread
2.2.1. The Example Architecture
2.2.2. The Thread Class
2.3. The Lifecycle of a Thread
2.3.1. Creating a Thread
2.3.2. Starting a Thread
2.3.3. Terminating a Thread
2.3.4. Pausing, Suspending, and Resuming Threads
2.3.5. Thread Cleanup
2.4. Two Approaches to Stopping a Thread
2.4.1. Setting a Flag
2.4.2. Interrupting a Thread
2.5. The Runnable Interface
2.6. Threads and Objects
2.6.1. Determining the Current Thread
2.7. Summary
2.7.1. Example Classes
3. Data Synchronization
3.1. The Synchronized Keyword
3.2. The Volatile Keyword
3.3. More on Race Conditions
3.4. Explicit Locking
3.5. Lock Scope
3.5.1. Synchronized Blocks
3.6. Choosing a Locking Mechanism
3.6.1. The Lock Interface
3.7. Nested Locks
3.8. Deadlock
3.9. Lock Fairness
3.10. Summary
3.10.1. Example Classes
4. Thread Notification
4.1. Wait and Notify
4.1.1. The Wait-and-Notify Mechanism and Synchronization
4.1.2. wait( ), notify( ), and notifyAll( )
4.1.3. Wait-and-Notify Mechanism with Synchronized Blocks
4.2. Condition Variables
4.3. Summary
4.3.1. Example Classes
5. Minimal Synchronization Techniques
5.1. Can You Avoid Synchronization?
5.1.1. The Effect of Registers
5.1.2. The Effect of Reordering Statements
5.1.3. Double-Checked Locking
5.2. Atomic Variables
5.2.1. Overview of the Atomic Classes
5.2.2. Using the Atomic Classes
5.2.2.1. Variable substitution
5.2.2.2. Changing algorithms
5.2.2.3. Retrying operations
5.2.3. Notifications and Atomic Variables
5.2.4. Summary of Atomic Variable Usage
5.2.4.1. Data exchange
5.2.4.2. Compare and set
5.2.4.3. Advanced atomic data types
5.2.4.4. Bulk data modification
5.3. Thread Local Variables
5.3.1. Inheritable Thread Local Variables
5.4. Summary
5.4.1. Example Classes
6. Advanced Synchronization Topics
6.1. Synchronization Terms
6.2. Synchronization Classes Added in J2SE 5.0
6.2.1. Semaphore
6.2.2. Barrier
6.2.3. Countdown Latch
6.2.4. Exchanger
6.2.5. Reader/Writer Locks
6.3. Preventing Deadlock
6.3.1. Deadlock and Automatic Lock Releases
6.3.2. Preventing Deadlock with Timeouts
6.4. Deadlock Detection
6.5. Lock Starvation
6.5.1. Lock Starvation and Reader/Writer Locks
6.6. Summary
6.6.1. Example Classes
7. Threads and Swing
7.1. Swing Threading Restrictions
7.2. Processing on the Event-Dispatching Thread
7.3. Using invokeLater( ) and invokeAndWait( )
7.4. Long-Running Event Callbacks
7.5. Summary
7.5.1. Example Classes
8. Threads and Collection Classes
8.1. Overview of Collection Classes
8.1.1. Collection Interfaces
8.1.2. Threadsafe Collection Classes
8.1.3. Thread-Unsafe Collection Classes
8.1.4. Thread-Notification Collection Classes
8.2. Synchronization and Collection Classes
8.2.1. Simple Synchronization
8.2.2. Complex Synchronization
8.2.3. Iterators and Enumerations
8.2.4. Thread-Aware Classes
8.3. The Producer/Consumer Pattern
8.4. Using the Collection Classes
8.5. Summary
8.5.1. Example Classes
9. Thread Scheduling
9.1. An Overview of Thread Scheduling
9.1.1. Priority-Based Scheduling
9.1.2. The Scheduling Process
9.1.3. Priority Exceptions
9.1.3.1. Priority inversion
9.1.3.2. Complex priorities
9.2. Scheduling with Thread Priorities
9.2.1. Other Thread-Scheduling Methods
9.3. Popular Threading Implementations
9.3.1. Green Threads
9.3.2. Windows Native Threads
9.3.3. Solaris Native Threads
9.3.4. Linux Native Threads
9.4. Summary
9.4.1. Example Classes
10. Thread Pools
10.1. Why Thread Pools?
10.1.1. Thread Pools and Throughput
10.1.2. Why Not Thread Pools?
10.2. Executors
10.3. Using a Thread Pool
10.4. Queues and Sizes
10.4.1. Rejected Tasks
10.5. Thread Creation
10.6. Callable Tasks and Future Results
10.6.1. The FutureTask Class
10.7. Single-Threaded Access
10.8. Summary
10.8.1. Example Classes
11. Task Scheduling
11.1. Overview of Task Scheduling
11.2. The java.util.Timer Class
11.2.1. Using the Timer
11.3. The javax.swing.Timer Class
11.3.1. Using the javax.swing.Timer Class
11.4. The ScheduledThreadPoolExecutor Class
11.4.1. Using the ScheduledThreadPoolExecutor Class
11.4.2. Using the Future Interface
11.5. Summary
11.5.1. Example Classes
12. Threads and I/O
12.1. A Traditional I/O Server
12.1.1. An Example Multithreaded Server
12.1.1.1. Using the multithreaded server
12.1.2. Scaling Using Traditional I/O
12.2. A New I/O Server
12.2.1. Nonblocking I/O
12.2.2. A Single-Threaded NIO Server
12.2.3. A Multithreaded New I/O Server
12.3. Interrupted I/O
12.4. Summary
12.4.1. Example Classes
13. Miscellaneous Thread Topics
13.1. Thread Groups
13.2. Threads and Java Security
13.3. Daemon Threads
13.4. Threads and Class Loading
13.5. Threads and Exception Handling
13.5.1. The ThreadDeath Class
13.6. Threads, Stacks, and Memory Usage
13.6.1. Stack Overflow Errors
13.6.2. Out of Memory Errors
13.6.3. Specifying Stack Sizes
13.6.4. Stack APIs
13.7. Summary
13.7.1. Example Classes
14. Thread Performance
14.1. Overview of Performance
14.1.1. Measuring Java Performance
14.2. Synchronized Collections
14.3. Atomic Variables and Contended Synchronization
14.3.1. The ConcurrentHashMap Class
14.4. Thread Creation and Thread Pools
14.5. Summary
14.5.1. Example Classes
15. Parallelizing Loops for Multiprocessor Machines
15.1. Parallelizing a Single-Threaded Program
15.1.1. Loop Scheduling and Load Balancing
15.1.1.1. Static or chunk scheduling
15.1.1.2. Self-scheduling
15.1.1.3. Guided self-scheduling
15.1.1.4. User-defined scheduling
15.1.2. Variable Classifications
15.1.2.1. Loop-private variables
15.1.2.2. Read-only variables
15.1.2.3. Storeback variables
15.1.2.4. Reduction variables
15.1.2.5. Shared variables
15.1.3. Loop Analysis and Transformations
15.1.3.1. Loop distribution
15.1.3.2. Loop isolation
15.1.3.3. Loop interchange
15.1.3.4. Loop reimplementation
15.1.4. Inner-Loop Threading
15.1.5. Loop Printing
15.2. Multiprocessor Scaling
15.2.1. A Simple Loop Test
15.2.2. A Reduction Variable Test
15.2.3. A Small Inner-Loop Test
15.2.4. A Printing Test
15.3. Summary
15.3.1. Example Classes
A. Superseded Threading Utilities
A.1. The BusyFlag Class
A.2. The CondVar Class
A.3. The Barrier Class
A.4. The RWLock Class
A.5. The ThreadPool Class
A.6. The JobScheduler Class
A.6.1. The DaemonLock Class
A.7. Summary
Index
About the Authors
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →