Java Thread Programming shows you how to take full advantage of Java's thread facilities: when to use threads to increase your program's efficiency, how to use them effectively, and how to avoid common mistakes. There is thorough coverage of the Thread API, ThreadGroup classes, the Runnable interface, and the synchronized operator. Extensive, complete, code examples show programmers the details of creating and managing threads in real-world applications.
Table of contents
- About the Author
- Structure of This Book
- Chapter 1—"Introduction to Threads"
- Chapter 2—"A Simple Two-Thread Example"
- Chapter 3—"Creating and Starting a Thread"
- Chapter 4—"Implementing Runnable Versus Extending Thread"
- Chapter 5—"Gracefully Stopping Threads"
- Chapter 6—"Thread Prioritization"
- Chapter 7—"Concurrent Access to Objects and Variables"
- Chapter 8—"Inter-thread Communication"
- Chapter 9—"Threads and Swing"
- Chapter 10—"Thread Groups"
- Chapter 11—"Self-Running Objects"
- Chapter 12—"Exception Callback"
- Chapter 13—"Thread Pooling"
- Chapter 14—"Waiting For the Full Timeout"
- Chapter 15—"Breaking Out of a Blocked I/O State"
- Chapter 16—"The SureStop Utility"
- Chapter 17—"The BooleanLock Utility"
- Chapter 18—"First-In-First-Out (FIFO) Queue"
- Appendixes: The Thread API and The ThreadGroup API
- Conventions Used in This Book
1. Introduction to Threads
- What Is a Thread?
- Why Use Multiple Threads?
- When Multiple Threads Might Not Be Good
- Java's Built-in Thread Support
- Easy to Start, Tough to Master
- 2. A Simple Two-Thread Example
- 3. Creating and Starting a Thread
- 4. Implementing Runnable Versus Extending Thread
5. Gracefully Stopping Threads
- Interrupting a Thread: interrupt()
- Suspending and Resuming Thread Execution
- Stopping a Thread
- The Best Replacement for stop(), suspend(), and resume()
- Daemon Threads
6. Thread Prioritization
- System Thread Priorities
- Thread Priority Constants
- Determining the Current Priority: getPriority()
- Changing the Priority of a Thread: setPriority()
- Thread States
- Priorities and Scheduling
- Voluntarily Relinquishing the Processor: Thread.yield()
- Thread-Scheduling Scenarios
7. Concurrent Access to Objects and Variables
- volatile Member Variable Modifier
- synchronized Method Modifier
- synchronized Statement Block
- static synchronized Methods
- Using the Class-Level Lock in a synchronized Statement
- Synchronization and the Collections API
- Speeding Concurrent Access
8. Inter-thread Communication
- The Need for Inter-thread Signaling
- The Wait/Notify Mechanism
- Object API Used for Wait/Notify
- When to Use notifyAll() Instead of notify()
- Missed Notification
- Early Notification
- CubbyHole Example
- Using join() to Wait for a Thread to Die
- Streaming Data Between Threads Using Pipes
- Using ThreadLocal and InheritableThreadLocal
9. Threads and Swing
- Why Isn't the Swing Toolkit Multithread-Safe?
- Using SwingUtilities.invokeAndWait()
- Using SwingUtilities.invokeLater()
- Using SwingUtilities.isEventDispatchThread()
- When invokeAndWait() and invokeLater() Are Not Needed
- The Need for Worker Threads in a GUI Setting
- Using a Worker Thread to Relieve the Event Thread
- Scrolling Text in a Custom Component
- Animating a Set of Images
- Displaying Elapsed Time on a JLabel
- Floating Components Around Inside a Container
10. Thread Groups
- What Are Thread Groups?
- Using getParent()
- Finding the Subgroups of a Thread Group
- Using the getThreadGroup() Method of Thread
- Finding All the Threads in a Thread Group
- Understanding Thread Group Security
- Using setMaxPriority() and getMaxPriority()
- Using interrupt()
- Deprecated Methods: stop(), suspend(), and resume()
- Class ThreadViewer
- 1. Introduction to Threads
- 11. Self-Running Objects
- 12. Exception Callback
- 13. Thread Pooling
- 14. Waiting for the Full Timeout
15. Breaking Out of a Blocked I/O State
- The read() Method Ignores Interrupts and Stop Requests
- Closing a Stream to Break Out of the Blocked State
- Throwing InterruptedIOException When Interrupted
- Using BufferedThreadedInputStream for Interruptible I/O
- 16. The SureStop Utility
- 17. The BooleanLock Utility
- 18. First-In-First-Out (FIFO) Queue
A. The Thread API
- Member Variables
- static methods
- Instance Methods
- Deprecated Methods
B. The ThreadGroup API
- enumerate(Thread, boolean)
- enumerate(ThreadGroup, boolean)
- uncaughtException(Thread, Throwable)
- Deprecated Methods
- A. The Thread API
- Title: Java Thread Programming
- Release date: August 1999
- Publisher(s): Sams
- ISBN: None
You might also like
Java Threads, Second Edition
Threads aren't a new idea: many operating systems and languages support them. But despite widespread support, …
Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions
Work with essential and advanced features of the Java programming language such as Java modules development, …
JavaFX Rich Client Programming on the NetBeans Platform
JavaFX is a state-of-the-art graphics toolkit that is now built into Java and can be easily …
Java 2D Graphics
One weakness of Java has been its graphics capabilities. Java 1.0 and 1.1 only included simple …