Forums Register Login

bookFlight

+Pie Number of slices to send: Send
Hi
There is something wrong with the implementation of my bookFlight method.
The DBTestRunner creates six different threads each of which book a specific number of seats. Now before running the
test the total # of seats on the flight xyz ( record # 14 )
was 48. After running the test, the total # of seats should have been reduced to 40 but I find that the total # of available seats on the
flight is 45 thus 5 bookings on this flight have failed.
Please look at the code for DBTestRunner and bookFlight method.


Any help is appreciated.
Thanks
Ravi
+Pie Number of slices to send: Send

I really can't tell.
But why are you assigning the modifyData array value for availableSeats as a String. Do you really want an int or Integer in that array element?
Mark
+Pie Number of slices to send: Send
Hi Mark
The record is in the form of String[] .
So, I have it as a String but convert it into int or Integer for manipulation purpose.
Is my implementation of bookFlight method okay? I am doing a lock-read-modify-unlock. Should I need to change it. Is there some problem with it.
Thanks
Ravi
+Pie Number of slices to send: Send
Hi Mark
If you look at the method in DataInfo class

What I am doing is directly modifying the seats field in the record and using that record to overwrite the previous record.
I hope what I did was correct. I have finished my submission however on running the test client , I found the problem area. I am sure that my submission will fail if I don't identify the problem area which could be either in lock-unlock or in read-modify.
Thanks
Ravi
Thanks
Ravi
+Pie Number of slices to send: Send
I am still wondering whether this problem is because of some thing wrong with my implementation of lock and unlock. Can you verify ?

Thanks
Ravi
+Pie Number of slices to send: Send
In the requirements does it have the signature of lock to throw an InterruptedException? I'd suggest placing a try catch in the lock method aounr the wait() call, then catch the Interrupted Exception there, and outside the while do your add() and remove the notifyAll().
And what happens in the unlcok method if by accident a record number is passed that is not locked?
Other than those two suggestions, Yuo lock and unlock look exactly like mine do.
Mark
+Pie Number of slices to send: Send
And the bookFlight method you have seems to be ok. the logic is very similar to mine. The only difference is that I broke it apart into a few methods instead of just one.
Mark
+Pie Number of slices to send: Send
Hi Mark

In the requirements does it have the signature of lock to throw an InterruptedException? I'd suggest placing a try catch in the lock method aounr the wait() call, then catch the Interrupted Exception there, and outside the while do your add() and remove the notifyAll().


I removed the InterruptedException in the method signature, I have used a try-catch and that solved all the problem. Now the booking is working perfectly. Thank you very much.
Why do I need to remove the notifyAll since after locking a record the waiting threads must be notified that the dbLock is free?


And what happens in the unlock method if by accident a record number is passed that is not locked?


To address this issue I have slightly modified the code to remove the lock on a record only after a check as given:

I hope this should fix the issue.
Thanks
Ravi
+Pie Number of slices to send: Send
 

Why do I need to remove the notifyAll since after locking a record the waiting threads must be notified that the dbLock is free?


Call it wierd, but I am thinking that when you lock a record, the other threads don't need to know. The ones that are waiting are waiting to see if they can get a record that is currently locked.
However, I am not sure if my thinking is entirely correct.
Mark
it's a teeny, tiny, wafer thin ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 860 times.
Similar Threads
Preliminary test fails! Threads problem
lock & unlock
Testing - Max's Book
Help needed JVM crashes while running the following program
DBTester and DBTestRunner in Max's book
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:13:27.