This week's book giveaway is in the Cloud forum.
We're giving away four copies of The Business Blockchain and have William Mougayar on-line!
See this thread for details.
Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI and client death

 
Don Resnik
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very happy with my locking code and it works great with multiple clients. My problem is that my lock-modify-unlock code is on the client side so if a client locks a row and then dies, that row stays locked. I tried working with a WeakReference of the client on the server side, but I never got it to work. I think it had to do with the garbage collection.
How important is it that I fix this part of the project? I have seen some posts that say you can get past this as long as you say you know this problem exists in your designchoices.txt. Also, my project docs say that what I am building is only an interim solution before the company goes for a web-based solution, which I think supports the ability to just state the problem and move on.
If it is imperative that dead clients properly release their locked records, could someone please help give me an idea of how to incorporate the lock-modify-unlock on the server side, or provide some insight on how the WeakReference is supposed to work?
Thanks
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Don,
If you still have the WeakReference code in your application, then you really should try and get it working. Leaving the code there but having it non functional could cost you marks.
As to whether you need to clean up after dead clients or not ... it does not appear to be a functional requirement, and many people have passed with good marks without having any code to clean up after client deaths. However many of us here believe that a professional solution will ensure that client deaths are handled in a suitable manner, and Kathy Sierra & Bert Bates also suggest that candidates consider this issue in their SCJP & SCJD book.
For WeakReference to work, you need several things:
  • a key which is uniquely identifiable with the client
    A common way of doing this is having a Connection Factory, where each client calls some getter or builder method on the factory which returns a unique reference to a remote object for that client. That unique object can be used as the key - or, if each client gets it's own instance of the Data class, then the instance of the Data class could be used as the key.
  • possibly some way of triggering a verification of whether locks have been released or not.
    One way you could do this is to have a separate thread which runs every 5 minutes checking the number of items currently in the WeakHashMap against the number of items your server knows has been explicitly added but not deleted. If the two numbers differ, then you can reset the calculated number, and notify all waiting threads.

  • Phil opened this thread to discuss issues with WeakReferences, which you may find interesting.
    Regards, Andrew
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic