*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes [URLyBird]How to check record validity in LockManager's lock() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "[URLyBird]How to check record validity in LockManager Watch "[URLyBird]How to check record validity in LockManager New topic
Author

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

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
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.


SCJP 1.4 SCJD
Leo Ho
Ranch Hand

Joined: Mar 31, 2005
Posts: 36
This's how I implement my lock:



HIH.

Leo
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
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

Joined: Mar 31, 2005
Posts: 36
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
 
wood burning stoves
 
subject: [URLyBird]How to check record validity in LockManager's lock()
 
Similar Threads
Locking strategy with singleton
Locking Issues
My Locking Approach
Reflections on singleton and synchronized methods
ClientID