Forums Register Login

B&S Version 2.3.3 locking

+Pie Number of slices to send: Send
Hi guys,
I read a lot about the locking problem from previous topics, but i could not find the answer to my problem.
Below is the DBMain interface from my instructons:

Below is my solution foor lock/isLocked/unlock and delete methods. (In delete method, i have bypassed the unlock method because once the record is deleted, unlock method throws an exception.)

I'm aware that my solution is a little bit strange, but i could not think of another way because of 'RecordNotFoundException' thrown from each method. I could have written the code like this in order to fit in this locking contract. Do you have any idea that my code is acceptable or not?
Have you thought of a similar approach?
Ulas Onder
SCJP, SCWCD
[Andrew: removed islocked() and unlock() methods]
[ March 15, 2004: Message edited by: Andrew Monkhouse ]
+Pie Number of slices to send: Send
Hi Ulas,
Welcome to this forum.

Originally posted by Ulas Onder:
I'm aware that my solution is a little bit strange, but i could not think of another way because of 'RecordNotFoundException' thrown from each method. I could have written the code like this in order to fit in this locking contract. Do you have any idea that my code is acceptable or not?
Have you thought of a similar approach?


I think you may be missing a requirement. All three methods are declared to throw RecordNotFoundException and according to the assignment instructions:


Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.


But the way these methods are written they would allow me to lock(-12345) even when there isn't a record number -12345. Also, as written they don't throw RecordNotFoundException under any circumstances. So I think you're not satisfying that requirement. For example, if I tried to delete an already deleted record your delete method (as written) would not throw a RecordNotFoundException as I think it should. Other than not handling the RecordNotFoundException the code looks good.
+Pie Number of slices to send: Send
Hi Ulas
I agree with George your delete method should throw RecordNotFoundException
if an attempt is made to delete an already deleted record.
What I did was to add a try catch block in my unlock method and listen
for RecordNotFoundExceptions.Then I search for the exceptions message ie
"Record Is Deleted". If that is the case the program keeps on execution
othwerwise throws RecordNotFoundException. You can take a similar approach and listen for your Deleted Record message whatever it is.
Logically speaking since its not possible to lock a deleted record (assuming your lock method validation works correctly)
that indicates an unlock call after a delete operation so it is safe to let the application run and remove the lock over the deleted record.
I hope this helps
Mehmet
+Pie Number of slices to send: Send
Hi Ulas,
I have removed some of your posted code, as we do not allow major sections of the assignment to be posted. The locking code is worth 20% of the assignment, and this is far too much to post in total. I have left the lock() method and the delete() method as points for people to discuss. See the question "What is the policy on posting questions I saw on the exam / details of how to do the assignment?" in the JavaRanch SCJD FAQ for more details.
In your lock() method I strongly recommend you do not swallow the InterruptedException - you should as a bare minimum be logging it. You should also consider what it means if your thread does get interrupted, and what state it is in at that point - can you really continue processing (as you are doing) or should you do something else?
Regards, Andrew
+Pie Number of slices to send: Send
Hi,
George said above:

But the way these methods are written they would allow me to lock(-12345) even
when there isn't a record number -12345.

Hi, George, and everyone,
My LockManager allows the client to lock any record number >= 0,
including record 200,000 (even if this record does not exist).
To lock record 200,000 when it does not exist is, of course, irresponsible
behavior on the client's part.
Is my design incorrect? Or will it be okay if I document that client's are not
allowed to lock arbitrary record numbers?
Thanks,
Javini Javono
+Pie Number of slices to send: Send
Hi Javini,
If your assignment instructions state:


// Locks a record so that it can only be updated or deleted by this client.
// If the specified record is already locked, the current thread gives up
// the CPU and consumes no CPU cycles until the record is unlocked.public void lock(int recNo) throws RecordNotFoundException;


And if they also state:


Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.


Then assuming that recNo = 12345 doesn't exist in your database file, don't you think that the examiner is going to be surprised if the following call doesn't throw a RecordNotFoundException:

Under what circumstances are you throwing RecordNotFoundException?
Now if my intention in writing the assignment instructions were to get you to throw the RecordNotFoundException when the user tries to lock a record number that doesn't exist, how could I have better communicated that intention than in the assignment instruction quotations above?
If that is the intention of the assignment instructions (and I don't see how another interpretation is possible) then it would be awfully easy for the examiner to determine whether I honored the contract specificed in the interface method comment.
[ March 15, 2004: Message edited by: George Marinkovich ]
+Pie Number of slices to send: Send
Thanks guys,
I put only a part of the delete method, it throws a RNFE, but not in the section i've posted.
Ulas Onder
SCJP, SCWCD
+Pie Number of slices to send: Send
 

Originally posted by George Marinkovich:
Hi Javini,
If your assignment instructions state:

Under what circumstances are you throwing RecordNotFoundException?
Now if my intention in writing the assignment instructions were to get you to throw the RecordNotFoundException when the user tries to lock a record number that doesn't exist, how could I have better communicated that intention than in the assignment instruction quotations above?
If that is the intention of the assignment instructions (and I don't see how another interpretation is possible) then it would be awfully easy for the examiner to determine whether I honored the contract specificed in the interface method comment.
[ March 15, 2004: Message edited by: George Marinkovich ]



Hi,
Thanks for your response, George, and thanks for unambiguously clarifying this point.
I will modify my LockManager so that the client is not allowed to lock and unlock
records which do not currently exist within the database (but, my LockManager will
allow the server to carry out this "magic").
Thanks,
Javini Javono
The fastest and most reliable components of any system are those that are not there. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1145 times.
Similar Threads
B&S: Quesion about RecNo
Do i have to create new exception for my interface
NX: URLy Bird 1.3.1 Hashmap (or Hashtable)
About:My URLyBird1.3.2 Locking
[URLyBirdHotel 1.3.3] Can I add more interfaces on Data.java?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:02:20.