osCache的问题,不解中

今天在使用spring-cache和osCache时发现了一个问题,当缓存目标方法发生异常时,会死锁。就是updateState.wait();造成的。在此做个标记,以后研究。目前使用EHCache就没有类似的问题发生
com.opensymphony.oscache.base.Cache#getFromCache
// Another thread is already updating the cache. We block if this
// is a new entry, or blocking mode is enabled. Either putInCache()
// or cancelUpdate() can cause this thread to resume.
if (cacheEntry.isNew() || blocking) {
    do {
        try {
            updateState.wait();
        } catch (InterruptedException e) {
        }
    } while (updateState.isUpdating());
    
    if (updateState.isCancelled()) {
        // The updating thread cancelled the update, let this one have a go. 
        // This increments the usage count for this EntryUpdateState instance
        updateState.startUpdate();
        
        if (cacheEntry.isNew()) {
            accessEventType = CacheMapAccessEventType.MISS;
        } else {
            accessEventType = CacheMapAccessEventType.STALE_HIT;
        }
    } else if (updateState.isComplete()) {
        reload = true;
    } else {
        log.error("Invalid update state for cache entry " + key);
    }
}

附上使用EHCache基于AOP方式的缓存配置文件,权当日记吧,算不上总结。
<!-- EHCache AOP -->
<bean id="eHCacheInterceptor"
	class="org.springframework.aop.interceptor.cache.EHCacheInterceptor" scope="singleton">
	<property name="refreshPeriods">
		<value>600</value>
	</property>
	<property name="defaultRefreshPeriod">
		<value>900</value>
	</property>
	<property name="identifiers">
        <props>
      		<prop key="java.util.Map">toString</prop>
        </props>
      </property>
</bean>
<bean id="eHCacheAdvisor"
	class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
	<property name="advice">
		<ref bean="eHCacheInterceptor" />
	</property>
	<property name="patterns">
		<list>
			<value>.*search.*</value>
			<value>.*get.*</value>
			<value>.*find.*</value>
		</list>
	</property>
</bean>
<bean id="eHCacheProxyCreator"
	class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
	<property name="beanNames">
		<value>*Service</value>
	</property>
	<property name="interceptorNames">
		<list>
			<value>eHCacheAdvisor</value>
		</list>
	</property>
	<property name="proxyTargetClass">
		<value>true</value>
	</property>
</bean>

你可能感兴趣的:(spring,AOP,thread,cache,Go)