用value为null的key连续两次调用getFromCache时,如果不向cache中放入value,且不调用cancelUpdate,则会发生死锁。
try {
Object obj= oscache.getFromCache(key, commentRefreshPeriod);
} catch (NeedsRefreshException e) {
//如果不能putInCache
oscache.cancelUpdate(key);
}
/**
* Cancels a pending cache update. This should only be called by a thread
* that received a {@link NeedsRefreshException} and was unable to generate
* some new cache content.
*
* @param key The cache entry key to cancel the update of.
*/
public void cancelUpdate(String key) {
getCache().cancelUpdate(key);
}
参考: