• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What's the point? -- Locks/LockManager

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic