Bob Hunt wrote:
My app is a "blog engine" like app. I store the first X (let's say 10) of the newly created entrys in a variable. It's is not a problem the users not get the up to date version of the entrys, because they could refresh the page if they wanted to. I make about 20 entrys in one day (setter), but I've got hundreds of thousands of visitors a day. It is not efficient (I think) to synchronize the getter methods (I've got quite a lot getter methods like the above, e.g. addons getting, ratings etc.). (No, I haven't got hundreds of thousands of visitors a day yet, but I want my app to be able to handle that)
Bob Hunt wrote:
I thought that Strings would be OK, and I'd have some trouble with HashMap. In the page above, a guy said "In the Java memory model, if there's no synchronization between the setter thread and the getter thread, it's possible that the getter thread will never get the updated value". I don't get it.
Let's say: "35 sec 300 millisec" I get the value, it is the old one. "35 sec 500 millisec" I set the value, than "50 sec xxx millisec" I try to get the new one? How come it is possible I won't get the new value ever?
Bob Hunt wrote: ... My question is: is getting and setting a variable atomic? I mean, in a multithreaded environment, Thread1 is about
to set variable s, while Thread2 is about to get "s". Is there any way the getter method could get something different
than the s's old value or the s's new value (suppose we've got only two threads)? ...
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton