While it's not part of the requirements, it's a useful bit of functionality indeed. In my implementation, all I had to add was The unlockAll() method did already exist; it's called from the close() function as well. While optional, nice to have functionality rarely comes as cheaply as thisOriginally posted by HS Thomas:
Option 3 is even better.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
.While optional, nice to have functionality rarely comes as cheaply as this
That's a true word; I guess I was just a little bit too glib there. You're right, whenever you venture into territory you don't know well (and RMI DGC and Unreferenced are unfamiliar territory for many of us, I guess) then seemingly simple code can hide a whole hornets' nest of problems. I guess we all have our tales of thrown-in freebies that turned into support nightmares.Originally posted by HS Thomas:
That innocuous line of code could be sitting on a powder keg for all I know, waiting to be lit.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
RMI DGC and Unreferenced are unfamiliar territory for many of us, I guess
RMI DGC and Unreferenced are unfamiliar territory for many of us, I guess
Originally posted by Eugene Kononov:
: "Would implementing the Unreferenced diminish the possible problems in case the premature collection happens, or does it increase the risk of problems?"
Eugene.
[ March 14, 2003: Message edited by: Eugene Kononov ]
Originally posted by HS Thomas:
Hi Max,
Someone like Eugene or Mark (preferably both) can be chairperson and draw up a definitive list of pros and cons from which any future discussions can be referenced.
Just an idea. Good for democracy.
regards
JavaRanch.com - 2002 Jolt Award Finalist
posted March 14, 2003 11:22 AM
--------------------------------------------------------------------------------
quote:
--------------------------------------------------------------------------------
RMI DGC and Unreferenced are unfamiliar territory for many of us, I guess
--------------------------------------------------------------------------------
Yeah, it takes some guts to dive in the details of it. Talking about Unreferenced, I noticed the following in the Garbage Collection of Remote Objects section of the RMI spec:
"Note that if a network partition exists between a client and a remote server object, it is possible that premature collection of the remote object will occur (since the transport might believe that the client crashed). Because of the possibility of premature collection, remote references cannot guarantee referential integrity; in other words, it is always possible that a remote reference may in fact not refer to an existing object. An attempt to use such a reference will generate a RemoteException which must be handled by the application".
In light of this information, my question for the RMI experts is this: "Would implementing the Unreferenced diminish the possible problems in case the premature collection happens, or does it increase the risk of problems?"
My understanding is that in this respect it won't make any difference whatsoever. By the time Unreferenced is called, the DGC has already decided that the Remote object is ripe for cleanup, and is engaged in that cleanup process. Once this has been completed, your Remote object will be unavailable whether you implement Unreferenced or not.Originally posted by Eugene Kononov:
In light of this information, my question for the RMI experts is this: "Would implementing the Unreferenced diminish the possible problems in case the premature collection happens, or does it increase the risk of problems?"
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Charles.<br />(SCJD2)
Invalidating the entire Connection object -- which is what the DGC action boils down to -- may be crude but seems the simplest way to handle this situation safely.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Charles.<br />(SCJD2)
Invalidating the entire Connection object -- which is what the DGC action boils down to
Maintain a boolean instance variable "closed" on Connection, which would be set by both close() and unreferenced(). Have LockManager check this right before it wants to grant the lock. If the Connection is closed, throw an exception or simply return w/o lock.
-- The entries of WeakHashMap are not released until the WeakHashMap is altered. If you do not call any mutator methods after populating the WeakHashMap, the values and WeakReference objects will never be dereferenced.
None whatsoever. The RMI DGC will have a bit of code somewhere that saysOr equivalent. WeakHashMaps, on the other hand, carry some performance penalty in reference traversal and management -- I can't recall having seen benchmarks though.Originally posted by HS Thomas:
Any light on performance overhead that comes with Unreferenced ?
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Eugene Kononov:
There are some additional considerations:
-- WeakHashMap uses its keys as weak references. That means that your map should be from client to record which is somewhat counterintuitive and it also prevents the client from locking multiple records.
-- The entries of WeakHashMap are not released until the WeakHashMap is altered. If you do not call any mutator methods after populating the WeakHashMap, the values and WeakReference objects will never be dereferenced.
-- Since WeakHashMap wraps its internal HashMap, there may be some significant performance overhead.
Every call to get() creates a new WeakReference object to enable equality testing of keys in the internal HashMap. The size() is an operation that takes time proportional to the size of the WeakHashMap, since it has to go through all the records to count those that have not been cleared. isEmpty() iterates through the collection to find a non-null key.
Of course, both WeakHashMap and Unreferenced will do the job and you will pass.
However, since Unreferenced is a standard solution to garbage collection in RMI, it seems more appropriate in the context of this assignment.
Using WeakHashMap instead of Unreferenced to clean the remote objects in RMI would be like coding your own merge sort instead of using the sort() method in the Collections interface.
Originally posted by HS Thomas:
Would
ensure that client locks will always dereference safely, whereas WeakHashMaps may never dereference under conditions quoted in :
regards
Originally posted by HS Thomas:
[QB]Sorry, couldn't resist the following :
The weightings are my own. QB]
*"A client connection can lock multiple record". I'm not sure why this gets a rating of 2, since it's not a requirement, and may actually be counter intuitive to the business needs. It would be equally arbitrary to design that "A client connectin can lock only a single record" deserves a 2.
"A client connectin can lock only a single record" deserves a 2.
I'd like to see this reflected in the chart, if you still willing to update it.
True. And looking at the properties and constraints of the problem (funcionality, mathematical, performance, whatever slant you take on it), a WeakHashMap forces you to map exactly the wrong way around. It makes the code much less expressive of the problem, and introduces performance penalties arbitrary constraints in the process, without justification (in my eyes) in simplicity, functionality, or performance. I've already beaten this subject to death; I won't repeat that here.Originally posted by Max Habibi:
Not sure why this should be counter intuitive Eugene : it's all a matter of context for the system you're in.
I believe it is an absolute mistake to look at the database as a flights database. The Data class you've been given makes this clear in no uncertain terms. Whoever wrote it went the extra (air) mile or two to make it absolutely, completely generic with zero, zip, zilch FBN dependence or FBN-specific assumptions. This is the class we are being asked to modify and enhance.In the airline industry, in which I have actually worked, there are usually business rules that disallow a Client Rep from booking more then a single flight at a time
They obviously are faster, as hashing gives you O(1) performance on most things where trees give you O(log N) performance. But we aren't comparing HashMaps to TreeMaps. We're comparing HashMaps to WeakHashMaps; AFAIK both have the same big-O behaviour. WeakHashMaps are slower but, as you note, it does not really matter much -- we've not been asked to develop for performance -- it's just another very small and minor exhibit in the case against a WeakHashMap.There are absolutely no significant performance overheads, since we're talking about millisecond here, and in some cases, hashmaps are actually faster then treemaps
You're suggesting complexity where there isn't any. Unreferenced will be called multiple times only when, after losing all remote references, you start handing out new references to remote client. That simply makes sense, and is not at all relevant in the FBN case.How do you think that unrefernced works? There are complexities in how the unreferenced works that make the above seem like a walk in the part. For example, did you know that unreferenced can be called several times.
If you can get it for free, yes... but not at the expense of expressivity of the problem domain, arbitrary restrictions on server functionality, use of non-standard API, conceptual complexity, cleanup predictability (gc involved), lock availability after cleanup (no notifyAll!), and performance.Actually, in a remote system, just as in a local system, it's best to automatically delete objects that don't have a reference. If you can get that for free by using a WeakHashmap, in addition to releasing the locks those objects hold, then using Unreferenced seems, to me, not to be the most elegant solution.
But all of the below instead:That is, to use the unreferenced structure, you need to
1. write a thread safe unreferenced method
2. implement the unreferenced interface,
and dig into the spec to see that it works safely.
3. Make one more call to the RemoteObject
In the WeakHashMap structure, you need:
None of the above.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Unsurprisingly, I don't agree at all with this assessment. From where I sit, it looks more complex: it is more invasive, makes your code harder to read, is conceptually more difficult, non-standard, and less predictable.Max Habibi wrote:Finally, to my point. The WeakHashMap implementation deserves more points, because it is less complex
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
ice is for people that are not already cool. Chill with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|