Meaningless Drivel is fun!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes one question on locking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "one question on locking" Watch "one question on locking" New topic

one question on locking

Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
can anyone tell me that since all of the data modification methods of data class are synchronized. then why do we have to create an overhead by creating a new lock control mechanism

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Even though the methods are synchronized does not stop the possibilty of client A modifying record 1 at the same time that client B is also modifying the same record. By locking the record you can assure that this won't happen. I know that synchronized methods puts a lock on the Data class, but think of it as a transaction demarcation, or something like that. Either way it is a requirement and a solution to that requirement.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Jeremy Squiers

Joined: Apr 03, 2002
Posts: 4
Put simply, the locking is used if you want to read a record, modify it (like take 1 away from the number of seats) and update it, all without another person modifying that record during that time. The synchronized methods will prevent two people from updating at the same time, but the locking will let you perform several operations on the record without it being changed by someone else and messing up your calculation.
[ April 04, 2002: Message edited by: Jeremy Squiers ]
I agree. Here's the link:
subject: one question on locking
It's not a secret anymore!