• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Denny's DVD locking

 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading now SCJD book by Andrew M., (I don't have my assignment yet) and I found following:

in class DvdDatabase


but DvdFileAccess class seems not to respect this. One client can take lock on some record, but other client may skip obtaining lock, call modifyDVD at any time and DVD will be modifed even if there is lock on it.

Can we take assumption (also on real assignment), that every client will perform any changes in order? :

getLockOnRecord
modify
releaseLockOnRecord

Thank you,
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

I don't have the book at hand here. In my assignment though, the update method (for example) needs the cookie param. So it cannot do its modifications without a correct cookie value, and this correct cookie value is retrieved by calling lock.

So this construction actually blocks the possibility of calling update without first calling lock.

But if you don't have a lock method returning the cookie, this is more complicated. I think Andrew's example is about this, and I'm sure there are enough threads here about this subject.
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you get assignment with cookies you will do the following for every update or delete operation

e.g.

lock(recNo,cookie)
update(recNo,cookie, data)
unlock(recNo,cookie)

so both update and unlock methods will verify correct cookie was pass to do the operation. When you lock recNo you will store that into HashMap so later on you can verify for update/delete operation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic