Hi Stefan, Thanks for your reply, but I still don't understand. Without synchronization, cache entries can only be overwritten when multiple threads have concurrent access, isn't it? It is not clear to me where the second thread comes from.
Best wishes, Martijn -----Oorspronkelijk bericht----- Van: Stefan Guggisberg [mailto:[EMAIL PROTECTED] Verzonden: vr 14-9-2007 17:47 Aan: [email protected] Onderwerp: Re: Synchronized methods in ItemManager hi martijn, On 9/14/07, Martijn Hendriks <[EMAIL PROTECTED]> wrote: > Hi all, > > The ItemManager has a small number of synchronized methods such as > getItem(ItemId id), which is heavily used. I cannot figure out why these > calls must be synchronized...can somebody give me an idea? Thanks! the ItemManager maintains a cache of NodeImpl/PropertyImpl instances. #getItem(itemId) e.g. is synchronized in order to guarantee the cache integrity. the following code fragment needs to be synchronized, otherwise cache entries might get accidentally overwritten: // check cache ItemImpl item = retrieveItem(id); if (item == null) { .... // create instance of item item = createItemInstance(id); } cheers stefan > > Best wishes, > > Martijn > > > -- > > Martijn Hendriks > <GX> creative online development B.V. > > t: 024 - 3888 261 > f: 024 - 3888 621 > e: [EMAIL PROTECTED] > > Wijchenseweg 111 > 6538 SW Nijmegen > http://www.gx.nl/ >
