aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "one question on locking" Watch "one question on locking" New topic
Author

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


SCJP, SCJD.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

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.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jeremy Squiers
Greenhorn

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: http://aspose.com/file-tools
 
subject: one question on locking