Synchronization

Multiple threads often must share access to common objects. For example, Listings 8.1 and 8.2 illustrate the effects of multithreading by having multiple executing threads write to the Java console, a common shared object. These examples do not require coordination or synchronization in the way the threads access the console window: Whichever thread is currently executing is able to write to the console window.

Sometimes you might want to coordinate access to shared resources. For example, in a database system, you might not want one thread to be updating a database record while another thread is trying to read it. Java enables you to coordinate the actions of multiple threads using synchronized methods and synchronized statements. ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.