DZone, Inc. Alex Miller ABOUT J A V A CONCURRENCY Core Java Concurrency Get More Refcardz! Visit #61 Core Java Concurrency From its creation, Java has supported key concurrency concepts such as threads and locks. This guide helps Java developers working with multi-threaded programs to understand the core concurrency concepts and how to apply them. Topics covered in this guide include built- in Java language features like Thread, synchronized , and volatile , as well as new constructs added in JavaSE 5 such as Locks, Atomics, concurrent collections, thread coordination abstraction, and Executors. Using these building blocks, developers can build highly concurrent and thread-safe Java applications. CONCEPTS This section describes key Java Concurrency concepts that are used throughout this DZone Refcard. T able 1: Java Concurrency Concepts Concept Description Java Memory Model The Java Memory Model (JMM) was defined in Java SE 5 (JSR 133) and specifies the guarantees a JVM implementation must provide to a Java programmer when writing concurrent code. The JMM is defined in terms of actions like reading and writing fields, and synchronizing on a monitor. These actions form an ordering (called the “happens-before” ordering) that can be used to reason about when a thread sees the result of another thread’s actions, what constitutes a properly synchronized program, how to make fields immutable, and more. Monitor In Java, every object contains a “monitor” that can be used to provide mutual exlusion access to critical sections of code. The critical section is specified by marking a method or code block as synchronized . Only one thread at a time is allowed to execute any critical section of code for a particular monitor. When a thread reaches this section of code, it will wait indefinitely for the monitor to be released if another thread holds it. In addition to mutual exlusion, the monitor allows cooperation t
java 来自淘豆网m.daumloan.com转载请标明出处.