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

What's the point? -- Locks/LockManager

 
Mark Cox
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion, calling lock/unlock methods is an unnecessary complication, which actually defeats the purpose of the synchronized keyword.
Here's how my system reserves seats:
Client calls reserveSeats method on database server. This method takes an int for the number of seats requested, and another int -- the record number. It checks if the seats are available, and if so subtracts appropriately.
The reserveSeats method is synchronized. Thus, all other clients will have to wait for the first one to finish before it can get into the reserveSeats method.
I just don't get all this unnecessary complication with locks, lock/unlock methods, LockManagers, ClientIDs... Using these things only defeats the purpose and elegance of synchronized methods. I don't understand why Sun would want us to misuse their language like this.
If I am wrong, please someone correct me. Moreover, if I neglect to implement lock/unlock methods will I fail (even if the system works fine)?
Any insight is appreciated! Thanks!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it is in the requirements, and one point of this exam is to see how you follow requirements. There are some points like command line that if you don't follow the requirements will result in automatic failure. I believe the implementation of a lock/unlocking scheme is one of those.
Mark
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Client calls reserveSeats method on database server. This method takes an int for the number of seats requested, and another int -- the record number. It checks if the seats are available, and if so subtracts appropriately.

Which object represents your "database server"? If it is the one that you bind to the registry, then it may happen that your clients' "reserve" requests run on the same thread (RMI spec allows that), and you have a problem. And if it is a unique object that your server creates, then you may have a "race condition". Either way, you need some sort of inter-client synchronization (such as lock/unlock )
Nice try, though.
Eugene.
[ January 21, 2003: Message edited by: Eugene Kononov ]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Cox:
[...] Client calls reserveSeats method on database server. [...]
Stop right there. There is no "reserveSeats" method in the database server.
There might be a reserveSeats method on a business-level server. But Sun explicitly steers you away from this by requiring that you have a client-side object that implements all the public methods of the Data class. See also this thread.
By using this design, you have reduced the reusability of your database server to zero and, worse, you have circumvented a couple of problems that Sun wants you to work through. I would expect you to be failed, but I should add that I've been surprised by the assessors before
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic