[Opensymphony-oscache] threading issues with NeedsRefreshException
snafu <[email protected]> Wed, 13 Jul 2005 14:10:54 CDT
| Newsgroups | gmane.comp.java.open-symphony.os-cache |
|---|---|
| Message-ID | <14905267.1121281920422.JavaMail.os-j2ee@opensymphony01.contegix.com> |
thats good news dres, any ETA on when the 3.0 release will be available? Also, could you share how you're thinking of handling stale entries going forward? Incidently, for those interested I chose to solve this issue as I initially proposed by returning the stale data to the first requester (the poor bastard) and kicking off an asynchronous thread to handle the expired cache entry's reload. I made use of Doug Lea's excellent util.concurrent package (available as part of the JDK 1.5 as java.util.concurrent). If you've never used it before it will blow you away, I use it for all my multithreading. (http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html). I use the PooledExecutor which provides a configurable thread pool for just such tasks.
Pseudocode:
catch(NeedsRefreshException nre){
try {
return nre.getCacheContent();
}
finally{
try{
//create a thread to handle the data refresh and reload the stale cache entry
//pass it any parameters it will need to pull the correct data and recreate the appropriate entry
MyRefreshThread thread = new MyRefreshThread(someParameters);
//pass the thread to the PooledExecutor's exectute method which will run the thread asynchronously
myPooledExecutor.execute(thread);
}
catch (Exception ex) {
log.error(ex);
}
}
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=4200&messageID=10545#10545