nissim,

I reviewed the refreshing cache discussion from last week so I think I
understand your issue a little better now.
some clarification:

you proposed implementing the refresh by extending the cache clearing
functionality - this is in clearCache(), right?  looks to me like, strictly,
clearCache should be synchronized along with getObject and addObject since
you're protecting the same resource (essentially, the hashtable) in each
case.  Unfortunately, this would have the effect (in you implementation) of
serializing access to the cache for all requests while any value is being
refreshed, e.g. value 'A' is being refreshed, cache is blocked, another
request comes in which wants value 'B', it gets to wait until the database
access to retreive 'A' is done.  Not desireable.  Would probably be safe,
though.  We could cook up a scheme that would work better, though, but'd be
more complicated.

Or are you concerned with the case where a user calls getObject from outside
the service, gets an exception because the value's not there then decides to
add it themselves.  This seems to be the case that Daniel is referring to.
In this case I would agree that a race condition also occurs and it's
probably outside the scope of the cache manager to address it.

Whew.  Threading issues can get so sweaty ;)

PaulO.


[shnip]

> 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.

[shnip]



------------------------------------------------------------
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