O'Reilly logo

Java™ Network Programming and Distributed Computing by Michael Reilly, David Reilly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.3. Synchronization

An important consideration when designing multi-threaded applications is conflict over access to data. If two threads are fighting for the same resource, and a mechanism to resolve access conflicts is not put into place, the integrity of the application is at stake. Built into the Java language are two mechanisms for preventing concurrent access to resources: method-level synchronization and block-level synchronization.

7.3.1. Method-Level Synchronization

Method-level synchronization prevents two threads from executing methods on an object at the same time. Methods that must be “thread-safe” are marked as synchronized. When a synchronized method of an object is invoked, a thread takes out an object lock, or monitor. If another ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required