1.If I use a static WeakHashMap in function of a Lockmanager and one client crashes, so the locked Record would in certain conditions be removed from the Collection. But the other threads waiting wouldn't be notified until a new thread would access the WeakHashMap, check the locked records, would lock the removed record and after completing his task, would notify the waiting threads. I'm right? Is this the disadvantage I would have to tolerate and which would also be accepted by the assignment?
2.
Because the value passed to the methods of Data.class is a primitive long and not a Wrapper-Instance of the Long-Class, the remote client wouldn't have a direct reference to the key-Object in the WeakHashMap? Is that right?
So after locking the record and putting him to the Collection and after leaving the synchronized block, it's possible that the Record would be removed from WeakHashMap when a client crashes at that moment?
3.If each client would have their own Data-Instance or share a singleton Data-Instance, there would be a difference concerning the use of WeakHashMap?
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
there is a notification issue that you can solve by using WeakReferences stored in a regular HashMap and registred with a ReferenceQueue. My LockManager class is based on them.
1.Does it mean, the ReferenceQueue is a certain Collection to which objects are put when their reachability changes?
2a.How do I register objects to the ReferenceQueue?
2b.How do I determine if an object is put to the ReferenceQueue due to its weak reference or for example due to its soft reference?
3.When does the notification call happen? It's integrated in a method of the ReferenceQueue?
Perhaps you can give me an example of your implementation, if it's ok?
1. You have a unique value for the key for the WeakHashMap
2. The lock entry in the WeakHashMap stays around until the reference to it is removed, i.e., the instance of Data created (I do it in a DataAdapter class which in turn is instantiated in the RemoteData class for network connection and directly in the case of no network connection) is no longer valid. This may be due to any number of reasons such as loss of connection, client crash etc.
this is really a good idea, but I have no the problem, that my lock and unlock method are a little bit different:
so, beside Long(recNo) and Data.this, I would have to store a long value for the cookie in the static Map. But that wouldn't cause a problem, if I would create instead of Long(recNo) an Array with recNo and cookie or a Record Object containing the two values. What do you think about it?
Besides, have a look to my comment in this thread (posted September 09, 2003 12:30 AM). I am not quite sure, but I think there are two issues in Bharat's lock implementation.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Hi Phil,
I'm still confused about ReferenceQueue. so, trying to implement your and Bharats' ideas, I have created a new Reference Class:
Maybe he went home and went to bed. And took this tiny ad with him:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|