-Igor
On 1/14/06, Jonathan Locke <[EMAIL PROTECTED]> wrote:
maybe the answer is to unsynchronize it and just let the markup load
twice on (probably very) rare occasions.
you should get the same result since the markup is immutable.
Johan Compagner wrote:
>
>
> MyObject myObject = concurrenthashmap.get(key)
> if(myObject == null)
> {
> synchronize(concurrenthashmap)
> {
> myObject = concurrenthashmap.get(key);
> if(myObject == null)
> {
> myObject = createMyObject();
> concurrenthashmap.put(key,myObject);
> }
> }
> }
> return myObject;
>
>
> If the concurrenthashmap was a just variable that you want to test or
> set like this?:
>
>
> MyObject myObject = myInstance;
> if(myObject == null)
> {
> synchronize(concurrenthashmap)
> {
> myObject = concurrenthashmap.get(key);
> if(myObject == null)
> {
> myObject = createMyObject();
> myInstance = myObject;
> }
> }
> }
> return myObject;
>
>
> then we would have the double check problem because the assignment of
> myInstance = myObject can be rearranged by the compiler
> so another thread would already read the reference but to an invalid
> not constructed/fully written object.
>
> But in our case we use a concurrenthashmap which if the key is not
> found does a sync internally and that sync is also used
> in the put again.
> So the question is if i understand synchronization at that level
> completely right that this piece of code:
>
> myObject = createMyObject();
> concurrenthashmap.put (key,myObject);
>
> should result in a fully constructed object in the concurrenthashmap
> because inside he put there is a sync yes?
>
> I am a bit confused because of this:
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
> <http://www.cs.umd.edu/%7Epugh/java/memoryModel/DoubleCheckedLocking.html >
> and then the part of "A fix that doesn't work" The big difference is
> ofcourse that we DO have a sync block on the null check
> in MyObject myObject = concurrenthashmap.get(key);
>
> This is all because i want to change MarkupCache.getMarkup()
> because i notice when i start hitting wicket in the repeater examples
> with 10 users at the same time almost all the time used is going into
> that method
> Because we are synching constantly on the markup cache and if the load
> is a bit high there is a large time spend because of that.
> And this is a pitty because after the initial webapplicaiton load and
> first pages hit. there doesn't have to be a sync what so ever because
> all the markup is already loaded!
> And this can be done by using a concurrenthashmap there but we do need
> to sync if there isn't a markup yet so that we don't load it twice
>
> If i change the code i get 10% more speed when doing the same test.
>
> johan
>
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop
