• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Zhixiong Pan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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.
 
Leo Ho
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic