The Senario of: Client A has the lock of a record. Client B trying to lock but he is in the waiting status because Client A locked. Client A crashed. Here, suppose the Map need to release the locking of Client A. That will be done in many different ways. I used a WeakHashMap but it's never released the locking of crashed client. That's because WeakHashMap release the weakReference only with a low memory. So, what can we do here please?
I didn't try it, but I will. What I did that I left the application working all the night. Morning it was the same situation when I left it. Client A still locking. other Clients were waiting. So, if I try to run gc() into the server, shall I keep it as a part of the server? I don't think so...
author and jackaroo
Hi Qusay Remember that there is no notification that the item has been removed from the WeakHashMap - you will have to have some way of checking whether the lock has been silently removed. The following scenario might work by accident:
A get's lock(5)
B attempts to get lock(5) - goes into wait
some time later (at least 20 minutes?) lock for 5 silently removed
C gets lock(7)
C releases lock(7) - calls notifyAll()
B wakes up, realises that there is noone holding lock 5, continues processing.
As you can see, this relied on a third party to wake up client B. Regards, Andrew