Book description
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
- Copyright
- About the Author
- Acknowledgments
-
Introduction
- 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
-
I. Threads
- 1. Introduction to Threads
- 2. A Simple Two-Thread Example
- 3. Creating and Starting a Thread
- 4. Implementing Runnable Versus Extending Thread
- 5. Gracefully Stopping Threads
- 6. Thread Prioritization
- 7. Concurrent Access to Objects and Variables
-
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
- Summary
-
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
- Summary
-
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
- Summary
-
II. Techniques
- 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
- 16. The SureStop Utility
- 17. The BooleanLock Utility
- 18. First-In-First-Out (FIFO) Queue
-
III. Appendixes
- A. The Thread API
-
B. The ThreadGroup API
- Constructors
-
Instance Methods
- activeCount()
- activeGroupCount()
- checkAccess()
- destroy()
- enumerate(Thread[], boolean)
- enumerate(Thread[])
- enumerate(ThreadGroup[], boolean)
- enumerate(ThreadGroup[])
- getMaxPriority()
- getName()
- getParent()
- interrupt()
- isDaemon()
- isDestroyed()
- list()
- parentOf(ThreadGroup)
- setDaemon(boolean)
- setMaxPriority(int)
- toString()
- uncaughtException(Thread, Throwable)
- Deprecated Methods
Product information
- Title: Java Thread Programming
- Author(s):
- Release date: August 1999
- Publisher(s): Sams
- ISBN: None
You might also like
book
Java Threads, Second Edition
Threads aren't a new idea: many operating systems and languages support them. But despite widespread support, …
book
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, …
book
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 …
book
Java 2D Graphics
One weakness of Java has been its graphics capabilities. Java 1.0 and 1.1 only included simple …