Programming Concurrency on the JVM doc

282 1.2K 0
Programming Concurrency on the JVM doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... three prominent options for concurrency on the JVM: • What I call the “synchronize and suffer” model • The Software-Transactional Memory model • The actor-based concurrency model I call the familiar Java Development Kit (JDK) synchronization model “synchronize and suffer” because the results are unpredictable if we forget to synchronize shared mutable state or synchronize it at the wrong level If we’re... for Concurrency, Modern Java/JDK Concurrency, Software Transactional Memory, Actor-Based Concurrency, and an epilogue In Chapter 1, The Power and Perils of Concurrency, on page 1, we will discuss what makes concurrency so useful and the reasons why it’s so hard to get it right This chapter will set the stage for the three concurrency models we’ll explore in this book Before we dive into these solutions,... depends on the number of cores available on the processor, and the number of concurrent threads for an application depends on the number of cores associated with its process 1.2 The Power of Concurrency We’re interested in concurrency for two reasons: to make an application responsive/improve the user experience and to make it faster Making Apps More Responsive When we start an application, the main... programming concurrency, this book is for you If you’re interested only in the solutions directly provided in Java and the JDK—Java threading and the concurrency library—I refer you to two very good books already on the market that focus on that: Brian Goetz’s Java Concurrency in Practice [Goe06] and Doug Lea’s Concurrent Programming in Java [Lea00] Those two books provide a wealth of information on. .. execution often takes on multiple responsibilities sequentially, depending on the actions we ask it to perform: receive input from a user, read from a file, perform some calculations, access a web service, update a database, display a response to the user, and so on If each of these operations takes only fractions of a second, then there may be no real need to introduce additional flows of execution;... application makes use of multiple threads or concurrent flows of execution On a single processor, these concurrent tasks are often multiplexed or multitasked That is, the processor rapidly switches between the context of each flow of execution However, only one thread, and hence only one flow of execution, is performed at any given instance On a multicore processor, more than one flow of execution (thread)... additional thread, to make the application responsive We need to delegate the task of counting and relieve the main event dispatch thread of that responsibility Not only can threads help make applications responsive, but they can help enhance the user experience Applications can look ahead at operations the user may perform next and carry out the necessary actions, such as indexing or caching some data the. .. Windows, run the program using the command java -server RaceCondition (asking it to be run in server mode on Windows), and on the Mac, run it using the command java -d32 RaceCondition (asking it to be run in client mode on the Mac) On Windows, we’d see something like this: OS: Windows 7 flag done set to true However, now on the Mac, we’ll see something like this: OS: Mac OS X Done! flag done set to true... primitives that makes the calling threads cross the memory barrier both when they enter and when they exit the synchronized block A thread is guaranteed to see the change made by another thread if both threads synchronize on the same instance and the change-making thread happens before the other thread; again, see What's This Memory Barrier?, on page 9 report erratum • discuss The Perils of Concurrency • 9... Concurrency, on page 243, we’ll review the solutions we’ve discussed in this book and conclude with some takeaway points that can help you succeed with concurrency Is it Concurrency or Parallelism? There’s no clear distinction between these two terms in the industry, and the number of answers we’ll hear is close to the number of people we ask for an explanation (and don’t ask them concurrently…or should I say . three separate concurrency solutions the modern Java JDK concurrency model, the Software Transac- tional Memory (STM), and the actor-based concurrency model. This. on the conference circuit both among speakers and attendees for their conversations and discussions. I thank the developers who took the time to read the

Ngày đăng: 15/03/2014, 02:20

Mục lục

  • Preface

    • Who's This Book For?

    • What's in This Book?

    • Is it Concurrency or Parallelism?

    • Concurrency for Polyglot Programmers

    • Examples and Performance Measurements

    • 1. The Power and Perils of Concurrency

      • Threads: The Flow of Execution

      • The Power of Concurrency

      • The Perils of Concurrency

      • Part 1—Strategies for Concurrency

        • 2. Division of Labor

          • From Sequential to Concurrent

          • Concurrency in IO-Intensive Apps

          • Speedup for the IO-Intensive App

          • Concurrency in Computationally Intensive Apps

          • Speedup for the Computationally Intensive App

          • Strategies for Effective Concurrency

          • 3. Design Approaches

            • Dealing with State

            • Persistent/Immutable Data Structures

            • Selecting a Design Approach

            • Part 2—Modern Java/JDK Concurrency

              • 4. Scalability and Thread Safety

                • Managing Threads with ExecutorService

                • 5. Taming Shared Mutability

                  • Shared Mutability != public

                  • Part 3—Software Transactional Memory

                    • 6. Introduction to Software Transactional Memory

                      • Synchronization Damns Concurrency

Tài liệu cùng người dùng

Tài liệu liên quan