Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one question on locking

 
Siddharth Mehrotra
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeremy Squiers
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic