Java concurrency
Encyclopedia
The Java language
and the JVM (Java Virtual Machine
) have been designed to support concurrent programming, and all execution in takes place in the context of threads
. Objects and resources can be accessed by many separate threads; each thread has its own path of execution but can potentially access any object in the program. The programmer must ensure read and write access to objects is properly coordinated (or "synchronized
") between threads. Thread synchronization ensures that objects are modified by only one thread at a time and that threads are prevented from accessing partially updated objects during modification by another thread. The Java language has built-in constructs to support this coordination.
. Every object in a JVM has a monitor associated with it. Such monitor-based concurrency was originally introduced with the Mesa programming language
.
The Java Language Specification does not say how the JVM designer should implement the multithreading
primitives specified, because there is so much variation among the various operating system
s and hardware
on which the JVM is expected to run.
Doug Lea
, who also participated in the Java collections framework implementation, developed a concurrency package
, comprising several concurrency primitives and a large battery of collection-related classes. This work was continued and updated as part of JSR
166 which was chaired by Doug Lea.
JDK 5.0 incorporated many additions and clarifications to the Java concurrency model. The concurrency APIs developed by JSR 166 were also included as part of the JDK for the first time. JSR 133
provided support for well-defined atomic operations in a multithreaded/multiprocessor environment.
Both the Java SE 6 and Java SE 7 releases introduced updated versions of the JSR 166 APIs as well as several new additional APIs.
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
and the JVM (Java Virtual Machine
Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
) have been designed to support concurrent programming, and all execution in takes place in the context of threads
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
. Objects and resources can be accessed by many separate threads; each thread has its own path of execution but can potentially access any object in the program. The programmer must ensure read and write access to objects is properly coordinated (or "synchronized
Synchronization (computer science)
In computer science, synchronization refers to one of two distinct but related concepts: synchronization of processes, and synchronization of data. Process synchronization refers to the idea that multiple processes are to join up or handshake at a certain point, so as to reach an agreement or...
") between threads. Thread synchronization ensures that objects are modified by only one thread at a time and that threads are prevented from accessing partially updated objects during modification by another thread. The Java language has built-in constructs to support this coordination.
Monitor synchronization in Java
The key synchronization concept for JVM concurrency is the monitorMonitor (synchronization)
In concurrent programming, a monitor is an object or module intended to be used safely by more than one thread. The defining characteristic of a monitor is that its methods are executed with mutual exclusion. That is, at each point in time, at most one thread may be executing any of its methods...
. Every object in a JVM has a monitor associated with it. Such monitor-based concurrency was originally introduced with the Mesa programming language
Mesa programming language
Mesa was an innovative programming language developed in the late 1970s at the Xerox Palo Alto Research Center in Palo Alto, California, United States. The language was named after the mesas of the American Southwest, referring to its design intent to be a "high-level" programming language.Mesa is...
.
The Java Language Specification does not say how the JVM designer should implement the multithreading
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
primitives specified, because there is so much variation among the various operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
s and hardware
Hardware
Hardware is a general term for equipment such as keys, locks, hinges, latches, handles, wire, chains, plumbing supplies, tools, utensils, cutlery and machine parts. Household hardware is typically sold in hardware stores....
on which the JVM is expected to run.
History
Since JDK 1.2, Java has included a standard set of collection classes, the Java collections frameworkJava collections framework
The Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures.Although it is a framework, it works in a manner of a library...
Doug Lea
Doug Lea
Doug Lea is a professor of computer science at State University of New York at Oswego where he specializes in concurrent programming and the design of concurrent data structures. He was on the Executive Committee of the Java Community Process and chaired JSR 166, which added concurrency utilities...
, who also participated in the Java collections framework implementation, developed a concurrency package
Java package
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...
, comprising several concurrency primitives and a large battery of collection-related classes. This work was continued and updated as part of JSR
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....
166 which was chaired by Doug Lea.
JDK 5.0 incorporated many additions and clarifications to the Java concurrency model. The concurrency APIs developed by JSR 166 were also included as part of the JDK for the first time. JSR 133
Java Memory Model
The Java memory model describes how threads in the Java programming language interact through memory. Together with the description of single-threaded execution of code, the memory model provides the semantics of the Java programming language....
provided support for well-defined atomic operations in a multithreaded/multiprocessor environment.
Both the Java SE 6 and Java SE 7 releases introduced updated versions of the JSR 166 APIs as well as several new additional APIs.
See also
- Concurrency (computer science)Concurrency (computer science)In computer science, concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other...
- Concurrency patternConcurrency patternIn software engineering, concurrency patterns are those types of design patterns that deal with multi-threaded programming paradigm.Examples of this class of patterns include:* Active Object* Balking pattern* Double checked locking pattern...
- Doug LeaDoug LeaDoug Lea is a professor of computer science at State University of New York at Oswego where he specializes in concurrent programming and the design of concurrent data structures. He was on the Executive Committee of the Java Community Process and chaired JSR 166, which added concurrency utilities...
- Java collections frameworkJava collections frameworkThe Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures.Although it is a framework, it works in a manner of a library...
- Java memory modelJava Memory ModelThe Java memory model describes how threads in the Java programming language interact through memory. Together with the description of single-threaded execution of code, the memory model provides the semantics of the Java programming language....
External links
- JDK 5.0 concurrency utilities
- Podcast from JavaPolis - 'Concurrency Utilities in JDK 5.0 by Brian Goetz'
- JavaOne 2005 - Concurrency Utilities in Practice
- JavaOne 2005 - Brian Goetz - Simpler, Faster, Better: Concurrency Utilities in JDK Software Version 5.0
- Podcast from JavaPosse - Interview with Brian Goetz on Concurrency in Java 5
- William Pugh's Java Memory Model page
- Java Concurrency Tutorial by Jakob Jenkov
- Thread Safe Java Programming by Vadym Ustymenko
- Java Concurrency Animations by Victor Grazi