O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java Threads and the Concurrency Utilities

Book Description

This concise book empowers all Java developers to master the complexity of the Java thread APIs and concurrency utilities. This knowledge aids the Java developer in writing correct and complex performing multithreaded applications.

Java's thread APIs and concurrency utilities are among its most powerful and challenging APIs and language features. Java beginners typically find it very difficult to use these features to write correct multithreaded applications. Threads and the Concurrency Utilities helps all Java developers master and use these capabilities effectively.

This book is divided into two parts of four chapters each. Part 1 focuses on the Thread APIs and Part 2 focuses on the concurrency utilities. In Part 1, you learn about Thread API basics and runnables, synchronization and volatility, waiting and notification, and the additional capabilities of thread groups, thread local variables, and the Timer Framework. In Part 2, you learn about concurrency utilities basics and executors, synchronizers, the Locking Framework, and the additional capabilities of concurrent collections, atomic variables, and the Fork/Join Framework.

Each chapter ends with select exercises designed to challenge your grasp of the chapter's content. An appendix provides the answers to these exercises. A second appendix explores how threads are used by various standard class library APIs. Specifically, you learn about threads in the contexts of Swing, JavaFX, and Java 8's Streams API.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. Part I : Thread APIs
    1. Chapter 1 : Threads and Runnables
      1. Introducing Thread and Runnable
        1. Creating Thread and Runnable Objects
        2. Getting and Setting Thread State
        3. Starting a Thread
      2. Performing More Advanced Thread Tasks
        1. Interrupting Threads
        2. Joining Threads
        3. Sleeping
      3. Summary
    2. Chapter 2 : Synchronization
      1. The Problems with Threads
        1. Race Conditions
        2. Data Races
        3. Cached Variables
      2. Synchronizing Access to Critical Sections
        1. Using Synchronized Methods
        2. Using Synchronized Blocks
      3. Beware of Liveness Problems
      4. Volatile and Final Variables
      5. Summary
    3. Chapter 3 : Waiting and Notification
      1. Wait-and-Notify API Tour
      2. Producers and Consumers
      3. Summary
    4. Chapter 4:Additional Thread Capabilities
      1. Thread Groups
      2. Thread-Local Variables
      3. Timer Framework
        1. Timer in Depth
        2. TimerTask in Depth
      4. Summary
  12. Part II : Concurrency Utilities
    1. Chapter 5: Concurrency Utilities and Executors
      1. Introducing the Concurrency Utilities
      2. Exploring Executors
      3. Summary
    2. Chapter 6 : Synchronizers
      1. Countdown Latches
      2. Cyclic Barriers
      3. Exchangers
      4. Semaphores
      5. Phasers
      6. Summary
    3. Chapter 7 : The Locking Framework
      1. Lock
      2. ReentrantLock
      3. Condition
      4. ReadWriteLock
      5. ReentrantReadWriteLock
      6. Summary
    4. Chapter 8 : Additional Concurrency Utilities
      1. Concurrent Collections
        1. Using BlockingQueue and ArrayBlockingQueue
        2. Learning More About ConcurrentHashMap
      2. Atomic Variables
        1. Understanding the Atomic Magic
      3. Fork/Join Framework
      4. Completion Services
      5. Summary
  13. Part III : Appendices
    1. Appendix A: Answers to Exercises
      1. Chapter 1: Threads and Runnables
      2. Chapter 2: Synchronization
      3. Chapter 3: Waiting and Notification
      4. Chapter 4: Additional Thread Capabilities
      5. Chapter 5: Concurrency Utilities and Executors
      6. Chapter 6: Synchronizers
      7. Chapter 7: The Locking Framework
      8. Chapter 8: Additional Concurrency Utilities
    2. Appendix B: Threading in Swing
      1. A Single-Threaded Programming Model
      2. Threading APIs
        1. SwingUtilities and EventQueue
        2. SwingWorker
        3. Timer
      3. Timer-Based Slide Show
  14. Index