Programming Concurrency on the JVM

Book description

More than ever, learning to program concurrency is critical to creating faster, responsive applications. Speedy and affordable multicore hardware is driving the demand for high-performing applications, and you can leverage the Java platform to bring these applications to life.

Concurrency on the Java platform has evolved, from the synchronization model of JDK to software transactional memory (STM) and actor-based concurrency. This book is the first to show you all these concurrency styles so you can compare and choose what works best for your applications. You'll learn the benefits of each of these models, when and how to use them, and what their limitations are.

Through hands-on exercises, you'll learn how to avoid shared mutable state and how to write good, elegant, explicit synchronization-free programs so you can create easy and safe concurrent applications. The techniques you learn in this book will take you from dreading concurrency to mastering and enjoying it. Best of all, you can work with Java or a JVM language of your choice - Clojure, JRuby, Groovy, or Scala - to reap the growing power of multicore hardware.

If you are a Java programmer, you'd need JDK 1.5 or later and the Akka 1.0 library. In addition, if you program in Scala, Clojure, Groovy or JRuby you'd need the latest version of your preferred language. Groovy programmers will also need GPars.

Table of contents

  1. Programming Concurrency on the JVM
    1. Copyright
    2. For the Best Reading Experience...
    3. Table of Contents
    4. What Readers Are Saying About Programming Concurrency on the JVM
    5. Preface
      1. Who’s This Book For?
      2. What’s in This Book?
      3. Is it Concurrency or Parallelism?
      4. Concurrency for Polyglot Programmers
      5. Examples and Performance Measurements
      6. Acknowledgments
    6. Chapter 1: The Power and Perils of Concurrency
      1. Threads: The Flow of Execution
      2. The Power of Concurrency
      3. The Perils of Concurrency
      4. Recap
    7. Part 1: Strategies for Concurrency
      1. Chapter 2: Division of Labor
        1. From Sequential to Concurrent
        2. Concurrency in IO-Intensive Apps
        3. Speedup for the IO-Intensive App
        4. Concurrency in Computationally Intensive Apps
        5. Speedup for the Computationally Intensive App
        6. Strategies for Effective Concurrency
        7. Recap
      2. Chapter 3: Design Approaches
        1. Dealing with State
        2. Exploring Design Options
        3. Shared Mutable Design
        4. Isolated Mutable Design
        5. Purely Immutable Design
        6. Persistent/Immutable Data Structures
        7. Selecting a Design Approach
        8. Recap
    8. Part 2: Modern Java/JDK Concurrency
      1. Chapter 4: Scalability and Thread Safety
        1. Managing Threads with ExecutorService
        2. Coordinating Threads
        3. Exchanging Data
        4. Java 7 Fork-Join API
        5. Scalable Collections
        6. Lock vs. Synchronized
        7. Recap
      2. Chapter 5: Taming Shared Mutability
        1. Shared Mutability != public
        2. Spotting Concurrency Issues
        3. Preserve Invariant
        4. Mind Your Resources
        5. Ensure Visibility
        6. Enhance Concurrency
        7. Ensure Atomicity
        8. Recap
    9. Part 3: Software Transactional Memory
      1. Chapter 6: Introduction to Software Transactional Memory
        1. Synchronization Damns Concurrency
        2. The Deficiency of the Object Model
        3. Separation of Identity and State
        4. Software Transactional Memory
        5. Transactions in STM
        6. Concurrency Using STM
        7. Concurrency Using Akka/Multiverse STM
        8. Creating Transactions
        9. Creating Nested Transactions
        10. Configuring Akka Transactions
        11. Blocking Transactions—Sensible Wait
        12. Commit and Rollback Events
        13. Collections and Transactions
        14. Dealing with the Write Skew Anomaly
        15. Limitations of STM
        16. Recap
      2. Chapter 7: STM in Clojure, Groovy, Java, JRuby, and Scala
        1. Clojure STM
        2. Groovy Integration
        3. Java Integration
        4. JRuby Integration
        5. Choices in Scala
        6. Recap
    10. Part 4: Actor-Based Concurrency
      1. Chapter 8: Favoring Isolated Mutability
        1. Isolating Mutability Using Actors
        2. Actor Qualities
        3. Creating Actors
        4. Sending and Receiving Messages
        5. Working with Multiple Actors
        6. Coordinating Actors
        7. Using Typed Actors
        8. Typed Actors and Murmurs
        9. Mixing Actors and STM
        10. Using Transactors
        11. Coordinating Typed Actors
        12. Remote Actors
        13. Limitations of the Actor-Based Model
        14. Recap
      2. Chapter 9: Actors in Groovy, Java, JRuby, and Scala
        1. Actors in Groovy with GPars
        2. Java Integration
        3. JRuby Akka Integration
        4. Choices in Scala
        5. Recap
    11. Part 5: Epilogue
      1. Chapter 10: Zen of Programming Concurrency
        1. Exercise Your Options
        2. Concurrency: Programmer’s Guide
        3. Concurrency: Architect’s Guide
        4. Choose Wisely
    12. Appendix 1: Clojure Agents
    13. Appendix 2: Web Resources
    14. Appendix 3: Bibliography
      1. You May Be Interested In…

Product information

  • Title: Programming Concurrency on the JVM
  • Author(s): Venkat Subramaniam
  • Release date: August 2011
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781934356760