我们使用Hibernate 4.3.10.Final,并为二级缓存启用了ehcache-2.9.0。 所有实体都配置为读写缓存。 在某些情况下,我们需要从ehcache中“逐出”一个实体,以便在下一次读取时可以将其从DB中强制刷新。我们使用以下代码将实体从ehcache中逐出:
Cache cache = sessionFactry.getCache();
if (cache != null) {
cache.evictEntity(PassengerRide.class, id);
}
有时,我们看到tomcat池的连接用完了(最大活动配置为400)。从线程转储中,我可以看到359个线程处于“等待”(驻留)状态,每个线程都在等待同一对象<0x00000003a5596f30>。检查线程“ http-nio-443-exec-3240”以供参考。这些线程中的每一个都在不同的对象上持有一个锁。我找不到在<0x00000003a5596f30>上持有锁的任何其他线程。同样,有70+个处于BLOCKED状态的线程正在等待锁定一个对象,该对象已被上述处于WAITING状态的线程锁定。检查线程“ http-nio-443-exec-3591”以供参考。处于“已阻塞”状态的线程正在尝试从ehcache获取或退出同一实体(不确定是否所有线程都在试图获取或退出同一实例)。
这是随机发生的,可能一周一次或十天一次。关于如何找出根本原因并解决的任何建议?
"http-nio-443-exec-3240" daemon prio=10 tid=0x00007f38c87a4000 nid=0x63bd waiting on condition [0x00007f38fa713000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000003a5596f30> (a java.util.concurrent.locks.ReentrantReadWriteLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:834)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireShared(AbstractQueuedSynchronizer.java:964)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(AbstractQueuedSynchronizer.java:1282)
at java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.lock(ReentrantReadWriteLock.java:730)
at net.sf.ehcache.store.CacheStore$4.call(CacheStore.java:196)
at net.sf.ehcache.store.CacheStore$4.call(CacheStore.java:192)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault.get(OnHeapCachingTier.java:334)
- locked <0x000000040847b890> (a net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault.access$200(OnHeapCachingTier.java:311)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier.get(OnHeapCachingTier.java:175)
at net.sf.ehcache.store.CacheStore.get(CacheStore.java:192)
at net.sf.ehcache.Cache.get(Cache.java:1734)
at org.hibernate.cache.ehcache.internal.regions.EhcacheTransactionalDataRegion.get(EhcacheTransactionalDataRegion.java:112)
at org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy.get(AbstractReadWriteEhcacheAccessStrategy.java:79)
at org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy.get(NonstopAwareEntityRegionAccessStrategy.java:108)
at org.hibernate.engine.internal.CacheHelper.fromSharedCache(CacheHelper.java:55)
at org.hibernate.engine.internal.CacheHelper.fromSharedCache(CacheHelper.java:67)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:598)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:452)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:213)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:275)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1106)
at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2587)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:996)
at com.xxxxx.ridedao.PassengerDAOImpl.getPassengerRide(PassengerDAOImpl.java:77)
"http-nio-443-exec-3591" daemon prio=10 tid=0x00007f38c8b46800 nid=0x6555 waiting for monitor entry [0x00007f3897af2000]
java.lang.Thread.State: BLOCKED (on object monitor)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault.get(OnHeapCachingTier.java:331)
- waiting to lock <0x000000040847b890> (a net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault.access$200(OnHeapCachingTier.java:311)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier.getValue(OnHeapCachingTier.java:299)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier.get(OnHeapCachingTier.java:199)
at net.sf.ehcache.store.CacheStore.get(CacheStore.java:192)
at net.sf.ehcache.Cache.get(Cache.java:1734)
at org.hibernate.cache.ehcache.internal.regions.EhcacheTransactionalDataRegion.get(EhcacheTransactionalDataRegion.java:112)
at org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy.get(AbstractReadWriteEhcacheAccessStrategy.java:79)
at org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy.get(NonstopAwareEntityRegionAccessStrategy.java:108)
at org.hibernate.engine.internal.CacheHelper.fromSharedCache(CacheHelper.java:55)
at org.hibernate.engine.internal.CacheHelper.fromSharedCache(CacheHelper.java:67)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:598)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:452)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:213)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:275)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1106)
at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2587)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:996)
at com.xxxxx.ridedao.PassengerDAOImpl.getPassengerRide(PassengerDAOImpl.java:77)
at sun.reflect.GeneratedMethodAccessor819.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
at com.sun.proxy.$Proxy49.getPassengerRide(Unknown Source)
at com.xxxxx.passenger.PassengerRideService.getPassengerRide(PassengerRideService.java:518)
at com.xxxxx.passenger.PassengerRideService$$FastClassBySpringCGLIB$$7b381e88.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at com.xxxxx.passenger.PassengerRideService$$EnhancerBySpringCGLIB$$f29afb12.getPassengerRide(<generated>)
at com.xxxxx.passenger.QRPassengerRideResource.getPassengerRide(QRPassengerRideResource.java:266)
我们在Ubuntu 16 VM上使用OpenJDK 1.8。我检查了OpenJDK错误列表,发现JDK-8149018似乎与我们遇到的问题相同。