Nissim wrote:
> 
> "Daniel L. Rall" wrote:
> >
> > Nissim wrote:
> > >
> > > The question is what do we lock to prevent two threads from (almost
> > > simultaneously) creating the same object.  We can lock the object which
> > > is refreshing, to make sure no one touches it while it's refreshing, but
> > > before an object is in the cache, there's nothing to lock.  Would it
> > > make sense to lock the whole cache while you build something to put in
> > > there?
> >
> > Yes.  The cache storage object should by synchronized whenever writes
> > are being made to it.
> 
> But even if we synchronized the addObject method (which is probably a
> good idea), that wouldn't prevent what Leon was talking about earlier.
> If Contact number 7 is not in the cache, and two threads both try to get
> it from the cache at nearly the same time, they'll both end up going to
> the DB for it, with the slower one overwriting the one that the faster
> one put in the cache first.

You are correct, and I don't see a way to prevent this.  Making the
getObject and addObject methods synchronized will not solve this problem
either--callers will have to synchronize a block.

-- 

Daniel Rall <[EMAIL PROTECTED]>
http://collab.net/ | open source | do the right thing


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to