The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
"I'm not back." - Bill Harding, Twister
What happens if one thread reads an old cookie value, rather than the latest value suppied by another thread, because no synchronization was performed while reading?
What happens if another thread manages to execute resize() (see source for HashMap) while you're trying to get() an "unchanging" value?
If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
"I'm not back." - Bill Harding, Twister
[Andrew]: nor the use of the lock manager in verifying the record number in update or delete.
[Jim]: Ummmm... I'm not sure what this means. When we verify a reord number for update or delete, we do have to look up the cookie in the HashMap, don't we? Are you saying that lookup need not be synchronized?![]()
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
If all the access methods (Data Class) to a shared resource (LockManager) are synchronized then we need not synchronize the methods inside the LockManager.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
"I'm not back." - Bill Harding, Twister
Mmmm, I'd be interested in seeing just what Max said
[Max]: The way this generally works is this. Your thread, say Thread #1, makes a local copy of the map(for efficiency), and does it's work there(this is Thread Memory, vs. Main Memory).
[Vlad]: The problem is if your database contains many records it will KILL the server:
[Max]: Vlad,
I think you might enjoy reading a bit more about this.
http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html#28458
he might have been suggesting that if you make a copy of the Map
You may even get a sort of partial copying
"Note that fail-fast behavior cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification."
"I'm not back." - Bill Harding, Twister
To find(), I just loop through the ArrayList, synchonizing each individual access to the List; then after I've retrieved an individual record (and am no longer synced on the List) I sync on that record while I look at it. So there's no need for one long sync of the list; just lots of little ones. If multiple threads are doing this simultaneously, it's no problem.
"I'm not back." - Bill Harding, Twister
Andrew have [allowed dirty reads] and have not lost a point for locking!
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
[Vlad] Have done something like this or you synhronized write/add/create methods also on HashSet and didn't synchronize read/find at all allowing dirty-reads like Max suggests?
[Andrew]Yes, I allowed dirty reads
[Andrew] Anyway, I did not incorporate read-locks into my design. But at the same time, the situation you were describing where a read could occur half way through a write causing garbled data could not occur in FBNS, since the provided methods getRecord() and modify() were both synchronized.
It seems that I have said something, what irritated you.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I was trying to differentiate between read locks, and synchronizing methods in the class (which prevents garbled data - what you are calling dirty reads). My definition of dirty reads is slightly different - my meaning is returning any dated data (or data which is known to be about to change) constitutes a dirty read. This was the definition I got from working with databases, where reading data prior to commit / rollback could result in a "dirty read" but not in reading garbled data.
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|