O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

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

Synchronizing Threads

The major problem in designing a multithreaded language is preventing collisions in which more than one thread attempts to modify the same object at the same time. Naturally, the CPU cannot actually do two things at once, but one thread might be halted in mid-calculation and another allowed to use the same data, resulting in a disaster.

Java provides the foundation for solving this problem in the Object class, the ultimate parent of all Java objects. Each object has an associated lock variable that can be manipulated only by the JVM. This lock provides a monitor mechanism that can be used to allow only one thread at a time to have access to an object.

In various Java books, “lock” and “monitor” are used interchangeably. ...

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