• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

I got a question on data locking.

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone:
I got a question on data locking. In network mode, if a client locked a record, and when it wants to update this record, this client shutdown, but it does not give up the lock. at the same time, another client wants to update this record too, it will check that whether this record is locked or not, so the answer is "locked". so, from now on, no client can updates this record.
So, I want to ask how to deal with this problem in server side? I think that why someone got 80/80, and someone got 44/80 in locking aspect.
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yanxin Zhao:
Hi everyone:
I got a question on data locking. In network mode, if a client locked a record, and when it wants to update this record, this client shutdown, but it does not give up the lock. at the same time, another client wants to update this record too, it will check that whether this record is locked or not, so the answer is "locked". so, from now on, no client can updates this record.
So, I want to ask how to deal with this problem in server side? I think that why someone got 80/80, and someone got 44/80 in locking aspect.



Dealing with orphan locks is not a requirement of the assignment. People who have both dealt with them and didn't have received 44/80 and 80/80. If it were a requirement, ignoring it would get an automatic failure.

All that said, its actually quite simple to handle these. You must detect the loss of a client and then unlock any locks held by that client. Detecting the client disconnect or failure requres some kind of keepalive. If you are using RMI you can use the Unreferenced interface and java.rmi.dgc.leaseValue property to do this. If you are using sockets you can use the setSoTimeout method to detect clients that have not sent a command in specific time.

For either of these to work, each client must have its own instance Data on the server. Here's what I do with RMI:
- server startup sets java.rmi.dgc.leaseValue and sun.rmi.dgc.checkInterval
- the server registers a DataAdapterFactory with the rmi registry
- a client gets a reference to the DataAdapter from the DataAdapterFactory
- the DataAdapterImpl on the server implements Unreferenced
- if the DataAdapterImpl goes unreferenced it closes the Data object, which requests that the LockManager unlock any records locked by that Data object.
 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply, Peter and Anton.
Peter, just likes what you said that it were not a requirement, so is that mean that I do not must to implement this function ?
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Er the 44/80 locking score is when locking deosn't work at all. Someone posted that ages ago. And it is a very typical score. Correct my memory if am wrong.
 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anna:
I do not agree with you. all right , if what you said is right, so why somebody got 0/80 in locking aspect. I think that If his or her lock mechanism can not working at all, I think he would got 0/80. this just my thought.
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you can get marks from attempting. You coded your complex locking mechanism and Sun found away to screw it all up, so you think that deserves a 0? That's bit harsh don't you think? But then better to be safe than sorry.
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Righto, there you go, it is unofficial. Posted back in June.

The Mysterious 44/80 Locking score
 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anna:
Yes, it is a bit harsh indeed. Maybe someone who got 0/80 is because of who did not realised that the record updating needs to lock the record. If that 's right, I can get 44/80 at least. Thanks very much for you found out which link to me.
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anton Golovin:


Hi, Yanxin.

I do think the mystery of 44/80 has been solved: it is given when someone does not check for record still existing after the waiting to unlock - in the lock method.



With all due respect, I think missing this aspect is almost unforgivable.
The signature of most if not all lock methods throws RecordNotFoundException. You only have to have a quick think for the reasons not found and cover those bases.
 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone:
I do not really understand how to use java.rmi.server.Unreferenced ? is that right that I let my class which implemented UnicastRemoteObject implementing Unreferenced, and write a method named unreferenced().
And in which method, first checking locks to ensure that no record was locked. if not, delete the record lock.
so is that can solve the problem that client shut down without unlock ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic