Originally posted by lydie prevost:
Hello,
I have a question concerning my fing method in data. I want to add "synchronized" but the find method in DB interface is not synchronized.
My understanding is that "synchronized" does not change the signature of a method. So I am OK to have it synchronized in Data even if it is not in the inteface.
Or should I wrap find in synchronized find method?
What do you think?
- Thank you
- Lydie
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
SCJP 1.4, SCJD
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
SCJP 1.4, SCJD
Originally posted by mike acre:
Oh bugger, I've overlooked this.
--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Originally posted by peter wooster:
Its not a big deal, the business logic could provide a second filtering to remove possibly invalid data, but since all you can do is book, the only invalid information is that the room may appear to be free when it isn't. If there are clients out there that can modify the name and location or delete the record then you may end up displaying truly invalid data. The final filtering must be done when booking is attempted and must be the sequence you described.
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Originally posted by peter wooster:
Its not a big deal, the business logic could provide a second filtering to remove possibly invalid data, but since all you can do is book, the only invalid information is that the room may appear to be free when it isn't. If there are clients out there that can modify the name and location or delete the record then you may end up displaying truly invalid data. The final filtering must be done when booking is attempted and must be the sequence you described.
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Originally posted by Bubba Smith:
in the fbns spec they ask to implement a locking on the whole db.
could you not just write lock the db before your search and unlock it after reading the data and not have any headaches w/ invalid data? performance aside.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP 1.4<br />(WIP) SCJD B&S v2.3.3
Originally posted by Anton Golovin:
Well, no, the problem is not that the collection is out of date, but that some records as retrieved may not match the search criteria. Consider the following:
your findRoom method may have:
synchronized find is called. an array of record numbers is returned.
synchronized read is called for each record.
If more than one client is accessing the database, something could happen between the find and the read for a record. That record may be a) deleted, b) deleted, then modified (overwritten), c) just modified (booked).
The a) option is handled by the RecordNotFoundException of the read method.
But what about the b) and c) options? It could result in the record displaying data which does not match the search criteria! What the findRoom method could be doing is returning wrong data to the client.
This is solved by rechecking a read record for matching the search criteria. We do not care if the record is out of date once it is passed to the client. It cannot be helped. But we do care that all the records passed to the client match the search criteria. And that is why every record needs to be rechecked.
There is an added benefit in that if you are writing a thin client. When you are rechecking the record in the business logic, it is returned on a partial match, as specified in the DB interface. Yet, the client is expected to show only complete matches (or complete matches on one of the criteria.) The business logic is the perfect place to achieve that. So my code a) rechecks the record matches the criteria, and b) checks that the record has at least one parameter which exactly matches criteria's parameter.
Sorry if I did not make myself clear the first post.
BTW, locking is achieved by only a few lines of code. Don't worry about it, you will get it done.
[ September 20, 2004: Message edited by: Anton Golovin ]
This parrot is no more. It has ceased to be. Now it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|