SCJP 1.4<br />SCJD 1.4
Originally posted by peter wooster:
With RMI you probably have an object per client on the server. This object can be the key to your HashMap. If you use an object per command on the server you will need to have some sort of session id that identifies the clients.
SCJP 1.4<br />SCJD 1.4
SCJP 1.4<br />SCJD 1.4
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse:
Hi Daniel,
I am not sure where you are going with the UID concept. If I am understanding you correctly, your lock method cannot be used unless you are using RMI. Normally you would want to re-use as much code as possible for both networked and standalone versions, but if your lock code is reliant on RMI, then your standalone version cannot use it. I think this will not be allowable according to the SCJD instructions.
Peter, I suspect, was talking about creating a new instance of the Data class per connection. At present you probably have a Proxy class which you are binding to the RMI registry, and every client connects to the same Proxy. The alternative is to have a Factory class that will create a new Proxy for each client.
If you have a unique instance of the Data class for each connected client then you can use that instance as your lock owner identifier. In addition, you have the potential to use either RMI's Unreferenced interface or a WeakHashMap to handle orphaned locks (if you decide to handle them).
Regards, Andrew
SCJP 1.4<br />SCJD 1.4
I am keeping my hashmap of thread names, but i can document that it won't apply to RMI.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse:
Hi Daniel,
What will be the benefit of keeping the hashmap of thread names if it does not apply to your networked solution?
When you are documenting why you are tracking the thread names, you will need to be explicitly clear that you understand why they cannot be used for RMI. I would suggest that such documentation would need to be in both your design decisions document, and in the source code itself.
You may even find that, if there is no outstanding benefit to tracking thread names in standalone mode, you may be better off removing the potential for confusion by removing the tracking of thread names.
Regards, Andrew
SCJP 1.4<br />SCJD 1.4
1) Is the sychronization of methods sufficient enough in RMI to prevent threading deadlock or other thread problems (excluding orphan locks)?
2) If I should not use a thread name hash map for local, how will I be able to prevent the assessor from running tests such as a thread trying [example shown above]
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse:
Hi Daniel,
That is difficult to answer because the question is so generic.
In your case, where I believe you are talking about synchronising methods in the Data class only, and your Data class is a Singleton, then you should be safe.
As soon as you start talking about any other synchronization (such as having a synchronized block using the RandomAccessFile object as the mutex) within your Data class, or having synchronization in other classes / instances of Data class, then all bets are off.
Also note that you mentioned deadlock in your question, which in context I have taken to mean thread deadlock not logical record deadlock which I am addressing in the next question.
Does this imply that you are preventing logical record deadlocks from multiple clients in RMI? That is (reusing your example) if client A requests a lock for record 0 then requests it again you will somehow handle the second request? Or a more complex example: client A requests a lock on record 0, client B requests a lock on record 1, client A requests a lock on record 1, client B requests a lock on record 0?
Regards, Andrew
SCJP 1.4<br />SCJD 1.4
Don't get me started about those stupid light bulbs. |