SCJP, SCJD, SCWCD
I think I'm right in saying that this method does not need to be synchronized because we are getting the lock on the static reservedDVDs object within the method body?
A related point is that it seems I shouldn't allow concurrent addition of records to the database. An obvious way to achieve this is by treating the addition of a record like an update to record number -1.
Maybe I don't need to worry too much about this as the ability to add/delete records must be provided in the class implementing DBAccess, but access to the functionality is not required from the GUI?
Another scenario where one might want to lock the whole database is when retrieving the initial list of DVDs, in order to prevent dirty reads? This possibility seems (to a fool such as I) to have been overlooked in the Denny's DVDs example?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
It is generally agreed that non-repeatable reads (slightly different to dirty reads) are acceptable, since it is impossible to ensure that you get repeatable reads unless you give up concurrent access.
SCJP, SCJD, SCWCD
SCJP, SCJD, SCWCD
SCJP, SCJD, SCWCD
Originally posted by Dan Murphy:
Hi Dan,
I hope I don't sound like a jerk - I'm very grateful for the advice you've provided both in your book and on this forum - but I don't think your book is consistent with the notion that dirty reads are OK, because it says on P.126 that Denny's DVDs prevents dirty reads - Dan
SCJP, SCJD, SCWCD
If client #1 reads locks-reads-unlocks record X, then client #2, say, lock-deletes-unlocks record X, then client #1 reads locks-read-unlocks record X+1. Client #1 is still getting a 'dirty' read of the entire DB, even if the read of a given record wasn't dirty at the time it was read. That is, client #1 will think that record X exists, when, in fact, it was deleted by client #2.
SCJP, SCJD, SCWCD
Originally posted by Dan Murphy:
Hi Max,
My sole concern is ensuring that client #1 cannot read a record while client #2 is updating it - this is what I consider to be a 'dirty' read.
It's a tiny ad only because the water is so cold.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|