I understand that you dont like my code.Could you please comment why? I know you like
the lockmanager solution better but is there any error on my code?
A couple of quick thoughts: you probably don't want to use an if statement in your unlock when dealing with locks.
Also, since this is the first iteration of development, I would probably just ignore the DB_LOCK issue all together for right now. Once you have the rest sorted out, that part will fit in easily.
Free software is a matter of liberty, not price.
Originally posted by Raffe Paffe:
Max:
mmmm, i dont get this more than i am not showing you the code you expcted ?
I am a little lost here. Whats next?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I don't agree with Max about the "if" statement in the unlock code.
The point is to write threadsafe code, it's not stylistic.
The problem here is that even as one thread could give the client the lock, another could take it away
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Make sense so far? I'm trying to do this in a way that doesn't steal the challange away from you, so be patient with me if I'm being somewhat circumspect.
Free software is a matter of liberty, not price.
Originally posted by Andrew Monkhouse:
Hi Max,
Based on the following, I can accept that we should always use the while statement.
We are talking about the unlock code, not the lock code. I cannot see any case where any other thread could take the lock away. The test is that the lock exists and that the current thread owns it. If any other thread can unlock this threads lock then there are logic bugs that must be resolved.
If I am missing something, can you please tell me.
Thanks, Andrew
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Free software is a matter of liberty, not price.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Free software is a matter of liberty, not price.
Free software is a matter of liberty, not price.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Is there a requirement that your calling class only handles IOExceptions?
Perhaps you could change it such that..
Free software is a matter of liberty, not price.
Originally posted by Raffe Paffe:
Andrew:
Thanks for your feedback!
I will have a look at your change.
I have another question about this design which i asked Max but he didnt answer. What about clients that read when i write. Will it work?
Max said yes, but i dont understand. If i start to write to a file and some other client reads the same record that i write will not the read be getting the wrong information? Every client has its own copy of the Data class and therfore File object. What ensures that the file will not be corrupted?
I havent change anything in Data except lock/unlock/criteriaFind and deprecated stuff. Is that enought?
Thanks again.
Originally posted by Andrew Monkhouse:
Hi Raffe,
This looks good. My comments (again) have nothing to do with functionality, just with styling:
I wont repreat my comment about DATABASE_LOCK and ALL_DATABASE_LOCKED.
You have two identical pieces of code ... the catch statements after each wait. Perhaps you could change it such that:
Think about whether that makes it easier to read and / or maintain or not?
Alternatively (IMHO a better solution), since you are just catching the InterruptedException and throwing an IOException, why not get rid of the try / catch blocks altogether and just throw the InterruptedException error? Since you are not handling the exception here, the logical place for the catch is in the calling class. Is there a requirement that your calling class only handles IOExceptions?
Regards, Andrew
Because of IO blocking, you're fine here. You might get 'old' data, but you're safe from 'bad' data, I think
Free software is a matter of liberty, not price.
Originally posted by Raffe Paffe:
Max:
Ok, can yuo explain more about this or post a link? Is it up to the java implemention to handle this?
As you have not commented on my unlock/lock implemenation should i understand that you think its ok(you know what i mean)?
Because of IO blocking, you're fine here.
Free software is a matter of liberty, not price.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Are you still implementing a LockManager class where Data.lock() calls LockManager.lock()?
Free software is a matter of liberty, not price.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Free software is a matter of liberty, not price.
Free software is a matter of liberty, not price.
SCJP 1.2, SCWCD, SCJD
Originally posted by Eugene Kononov:
[b]
Vector is a legacy collection, -- it should never be used. You have an ArrayList to achive the same purpose, and you can make it synchronized if you want to. For the SCJD assignment, the most appropriate collection to store the record locks is the hash map, -- I think everybody agrees with that.
Eugene.
Originally posted by Rajesh Rajesh:
This would remove the word 'synchronized' from the entire Data class.
Am I right ?
[ April 21, 2003: Message edited by: Rajesh Rajesh ]
If the question in essay exam asks how do you plan to upgrade Data for more than one database, the answer would be to have a static Map for every Database.
Qusay
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Qusay
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|