Jump to content

Java concurrency

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 18.239.6.217 (talk) at 20:39, 26 May 2008 (Monitor synchronization in Java). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Introduction

Java is a programming language (and API) which has been designed to support concurrent programming, and all execution in the language takes place in the context of a thread. It is important for a Java programmer to understand both the power and limitations of Java threads.

In the JVM (Java Virtual Machine), 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 that threads do not interfere with each other, and that resources are properly coordinated (or "synchronized") during both read and write access. The Java language has built-in constructs to support this coordination.

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 systems and hardware on which the JVM is expected to run.

Monitor synchronization in Java

The key synchronization concept in Java is the monitor. Every object in a JVM has a monitor associated with it. Such monitor-based concurrency was originally introduced with the Mesa programming language.

Changes in Java 5

Java 5 incorporated many additions and clarifications to the Java concurrency model. JSR 133 provided support for well-defined atomic operations in a multithreaded/multiprocessor environment, opening the door to JSR 166, a large battery of concurrent programming APIs.

See also

References

  • Goetz, Brian (2006). Java Concurrency in Practice. Addison Wesley. ISBN 0-321-34960-1. {{cite book}}: Unknown parameter |coauthors= ignored (|author= suggested) (help)
  • Lea, Doug (1999). Concurrent Programming in Java: Design Principles and Patterns. Addison Wesley. ISBN 0-201-31009-0.