• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Network Errors and Locking

 
Jack Gold
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am almost ready to submit, but one issue has been nagging at me, especially considering there is not a reliable way to test it.

What if a thread locks a record and then loses network connectivity before it is able to unlock it? Then, other threads will not be able to access this record and will wait indefinitely.

I could possibly establish a maximum wait time for the thread, but this does not solve the problem of unlocking the offending record.

Alternatively, I could maintain time stamps of each lock and periodically sweep the list of locked records and unlock any that have been locked for more than a fixed ammount of time.

Is there an easier solution? Is this beyond the scope of the assignment?

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 Jack,

Yes, this is beyond the scope of the assignment.

As to how you can handle it: it depends on how you have been developing your assignment.

If you are using Sockets, you can catch the Exception when the client disconnects, and clean up then.

If you have an RMI connection factory, then you can use the Unreferenced interface to clean up locks.

For both Sockets and RMI connection factory, if you don't have cookies it is also possible to use a WeakHashMap to hold the owners/records locked information. You have to take care what you use to identify the owner, and you have to have a daemon thread to watch this solution, but it can be a neat solution.

As always - only hints have been given so far.

Regards, Andrew
 
Jack Gold
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew, Thanks very much. I already found one of your older posts and decided this was beyond the scope of the assignment. I documented the potential issue and moved on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic