Originally posted by Ailsa Cape:
A friend told me I would get the best answers after I had written my search key words and entered the member id “47425” in search page. It is true. That’s terrific!
Originally posted by Ailsa Cape: b) Should I use all synchronized modifiers only in LockManager and RemoteData classes, the latter of which in the server side is an adapter of Data class, instead of adding those modifiers in Data class?
Originally posted by Ailsa Cape:
By the way, my assignment is B&S.
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 Kai:
case a can not appear if you synchronize all actions that require setting
the pointer on the same entity, and if you don't leave this synchronized context during the important operations (e. g. don't leave it between seeking and the actual deleting).
Could you share more specific ideas about how to synchronize all actions in update method? I can’t figure out a way to treat a series of actions as atomic. And I don’t quite understand the FILE_SYNCHRONIZER variable in your example code. Does this represent raf object?
Well, apart from the fact that this code won't compile , I think you are showing the right concepts there, so it should be OK.Originally posted by Ailsa Cape:
In server mode, every client in my design will get its own unique instance of Data class and share a single instance of RandomAccessFile class. Would the following codes do the trick?
From memory I was working on the assumption that there could only be one instance of ThreadsafeDatabase4, otherwise the synchronized methods would not work. As long as there is only one instance, then no matter how many threads there are, they will all synchronize on the same object.Originally posted by Ailsa Cape:
I have just searched one post ThreadsafeDatabase4 [...] In the class ThreadsafeDatabase4, you didn’t use the means of synchronizing blocks. I wanna ask if two threads separately run in read and update methods simultaneously, will this make the underlying file pointer changed unexpectedly? Is it due to more than one instance of RandomAccessFile?
Yes you can. If you do this, you must ensure that clients only call your Data class. You might want to consider changing your access level of the classes / methods behind the Fa�ade to restrict access.Originally posted by Ailsa Cape:
My instructions state that Your data access class must be called “Data.java”, must be in a package called “suncertify.db”, and must implement the DBMain interface. Can I make the Data class be a Fa�ade to several “invisible” classes that do the work behind the scenes?
That is my reading of the instructions - the Data class must be written in such a way that it meets all the contractual obligations of the interface. You cannot rely on client code to meet your contractual obligations.Originally posted by Ailsa Cape:
As to the synchronization modifiers, do you mean I should make thread safe in the Data class rather than in my RemoteData class?
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:
using synchronized methods only works as long as you only have one instance of the class.
Originally posted by Andrew:
If you do this, you must ensure that clients only call your Data class. You might want to consider changing your access level of the classes / methods behind the Fa�ade to restrict access.
I wish you could give me more hints about how to change my access level of the classes behind the Fa�ade to restrict access for I don’t quite catch on it.
would you like to introduce other Java books written by you to me?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Your mother is a hamster and your father smells of tiny ads!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|