Hi all,
I am almost read done with my assignement.
Analazing result of the other I can see that almost all people preparing URLBirld assignement have lost a lot of scores for locking. Nobody from them knows a reason.
I have first tried to use ReadWriteLock allowing to read simultaniously as
long as nobody writes and so. Having 2 objects for synchronization
(1 for read-write lock) and one for lock/unlock functionality I run to the problems with dead-locks. I decided to simplify everything and I synchronize now everything on the cashmap containing all records (I use database cashing): read, find, update, create, delete, lock, unlock.
All the books for certification preparation do the same(they just synchronize on this, what is alsmost the same what I do).
However, I beleive that I have to optimize somehow read/find.
Some people do not synchronize read/find at all, saying they allow dirty-reads.
I don't really understand how it should work then: I beleive it is inacceptable to deliver corrupted data to the client(e.g. instead of hotel name Sheraton -> Shera). To find the records I have to iterate over my HashMap, which can lead to the exception if any other
thread changes any record, because of fail-fast mechanism of HashMap Iterator).
Max have said that threads make their local copies ob this object, so fail-fast exception cannot occur as well as non-consistant values cannot appear.
Honestly saying I don'r really understand why: If he is right what is the sense of fail-fast mechanism of Iterator (when can it happen then???)
Could somebody help me to understand this issue:
1) Is it Ok to synchronize on read/find blocking the whole database each, but having the code simple and stable?
2) If not does somebody used RWLock and it was integrated to Locka for lock/unlock?
3) If you allow dirty locks and and also cash the database, how do you iterate over this HashMap or List?
Thanx,
Vlad