为什么ehcache 3.7.1在org.ehcache.impl.internal.concurrent.ConcurrentHashMap.transfer

时间:2019-05-20 04:10:58

标签: java spring ehcache

我在方法中使用Spring's @Cacheable,并使用Ehcache作为实现,方法和缓存在被调用时都可以正常工作,但是在放入缓存结果时,第三个调用被阻塞。

我调试了代码,发现它在这里阻塞了:

org.ehcache.impl.internal.concurrent.ConcurrentHashMap.transfer(ConcurrentHashMap.Node<K, V>[] tab, ConcurrentHashMap.Node<K, V>[] nextTab)

存在无限循环

我的代码就像

AService.java

...

@Autowired
private BService bService;

...

@Cacheable(cacheManager = "ehcacheManager", value = "cache_10s", key = "'a_' + #appKey'", sync = true)
public List<xxx> methodA(String appKey) {
    return bService.methodB(convertFrom(appKey));
}
...

BService.java

...
@Cacheable(cacheManager = "ehcacheManager", value = "cache_10s", key = "'b_' + #parameterId", sync = true)       
public List<xxx> bMethod(Long parameterId) {
        //block after return
        return parameterId;
    }

...

Spring缓存配置

@Configuration
public class EhcacheConfiguration {

    @Bean
    public JCacheManagerFactoryBean jCacheManagerFactoryBean() throws IOException {
        JCacheManagerFactoryBean jCacheManagerFactoryBean = new JCacheManagerFactoryBean();
        jCacheManagerFactoryBean.setCacheManagerUri(new ClassPathResource("ehcache.xml").getURI());
        return jCacheManagerFactoryBean;
    }

    @Bean(name = "ehcacheManager")
    public JCacheCacheManager jCacheCacheManager(@Qualifier("jCacheManagerFactoryBean") CacheManager jCacheManagerFactoryBean) {
        JCacheCacheManager jCacheCacheManager = new JCacheCacheManager();
        jCacheCacheManager.setCacheManager(jCacheManagerFactoryBean);
        return jCacheCacheManager;
    }
}

ehcache.xml

<config
        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
        xmlns='http://www.ehcache.org/v3'
        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">

    <cache alias="cache_10s">
        <expiry>
            <ttl unit="seconds">10</ttl>
        </expiry>
        <heap unit="entries">10000</heap>
    </cache>

    <cache alias="cache_30s">
        <expiry>
            <ttl unit="seconds">30</ttl>
        </expiry>
        <heap unit="entries">10000</heap>
    </cache>

    <cache alias="cache_1min">
        <expiry>
            <ttl unit="minutes">1</ttl>
        </expiry>
        <heap unit="entries">10000</heap>
    </cache>

    <cache alias="cache_5min">
        <expiry>
            <ttl unit="minutes">1</ttl>
        </expiry>
        <heap unit="entries">10000</heap>
    </cache>

    <cache alias="cache_1h">
        <expiry>
            <ttl unit="hours">1</ttl>
        </expiry>
        <heap unit="entries">10000</heap>
    </cache>
</config>

线程转储

"main" #1 prio=5 os_prio=0 tid=0x00007ff6a8018800 nid=0x591 runnable [0x00007ff6b1686000]
   java.lang.Thread.State: RUNNABLE
    at org.ehcache.impl.internal.concurrent.ConcurrentHashMap.transfer(ConcurrentHashMap.java:2574)
    at org.ehcache.impl.internal.concurrent.ConcurrentHashMap.addCount(ConcurrentHashMap.java:2374)
    at org.ehcache.impl.internal.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:2020)
    at org.ehcache.impl.internal.store.heap.SimpleBackend.compute(SimpleBackend.java:101)
    at org.ehcache.impl.internal.store.heap.OnHeapStore.computeAndGet(OnHeapStore.java:1196)
    at org.ehcache.core.Ehcache$Jsr107CacheImpl.compute(Ehcache.java:198)
    at org.ehcache.jsr107.Eh107Cache.invoke(Eh107Cache.java:340)
    at org.springframework.cache.jcache.JCacheCache.get(JCacheCache.java:80)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:363)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:326)
    at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy111.getByParameterId(Unknown Source)
    at AService(AService.java:131)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.cache.interceptor.CacheInterceptor$1.invoke(CacheInterceptor.java:52)
    at org.springframework.cache.interceptor.CacheAspectSupport.invokeOperation(CacheAspectSupport.java:344)
    at org.springframework.cache.interceptor.CacheAspectSupport$1.call(CacheAspectSupport.java:366)
    at org.springframework.cache.jcache.JCacheCache$ValueLoaderEntryProcessor.process(JCacheCache.java:121)
    at org.ehcache.jsr107.Eh107Cache.lambda$invoke$0(Eh107Cache.java:346)
    at org.ehcache.jsr107.Eh107Cache$$Lambda$280/704445524.apply(Unknown Source)
    at org.ehcache.core.Ehcache$Jsr107CacheImpl.lambda$compute$0(Ehcache.java:194)
    at org.ehcache.core.Ehcache$Jsr107CacheImpl$$Lambda$284/1052362101.apply(Unknown Source)
    at org.ehcache.impl.internal.store.heap.OnHeapStore.lambda$computeAndGet$21(OnHeapStore.java:1207)
    at org.ehcache.impl.internal.store.heap.OnHeapStore$$Lambda$285/1827686351.apply(Unknown Source)
    at org.ehcache.impl.internal.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1934)
    - locked <0x0000000785a30620> (a org.ehcache.impl.internal.concurrent.ConcurrentHashMap$ReservationNode)
    at org.ehcache.impl.internal.store.heap.SimpleBackend.compute(SimpleBackend.java:101)
    at org.ehcache.impl.internal.store.heap.OnHeapStore.computeAndGet(OnHeapStore.java:1196)
    at org.ehcache.core.Ehcache$Jsr107CacheImpl.compute(Ehcache.java:198)
    at org.ehcache.jsr107.Eh107Cache.invoke(Eh107Cache.java:340)
    at org.springframework.cache.jcache.JCacheCache.get(JCacheCache.java:80)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:363)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:326)
    at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy126.obtainExperimentConfigByKey(Unknown Source)
    at ...
    at ...
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

0 个答案:

没有答案