• 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

[URLyBird]How to check record validity in LockManager's lock()

 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

In LockManager's lock, my while loop is condition on record's validity.But i dont get a good approach to check that validity. I think there should be two ways:

1. add a method isValid() in Data. And in LockManager's lock, call that method.
2. pass a reference of Data to LockManager through constructor, then synchronize and check Data's ioHand.

Which will be better?Thanks very much for your reply.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This's how I implement my lock:



HIH.

Leo
 
Zhixiong Pan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Leo,

1. I choose constructor which take charge of getting a reference of Data object(equals your DBMain).

2. Why call dataServeice.read()? Only check the validity!

3. I think you should scan other posts about how to lock in this forum before coding.
 
Leo Ho
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pan, the method signature of my lock() needs to throw RecordNotFoundException (sorry, I didn't remember to type it in the code of the previous post), thus I need to do a read to make sure that the record do exist before trying to insert the lock into the map.

I don't pass DBMain into the constructor since my DBMainImpl is specific for each client while the LogManager must be singleton - by passing it to the method, I can both check the validity and have a unique instance for locking purpose.

Not sure if the read() is what you meant by "validity"???

Leo
 
reply
    Bookmark Topic Watch Topic
  • New Topic