Java 使用getKeysWithExpiryCheck()方法时ehcache密钥集超时
我使用ehcache来控制用户会话,每隔一段时间我就会在用户登录时的日志中看到这个错误Java 使用getKeysWithExpiryCheck()方法时ehcache密钥集超时,java,cluster-computing,ehcache,terracotta,Java,Cluster Computing,Ehcache,Terracotta,我使用ehcache来控制用户会话,每隔一段时间我就会在用户登录时的日志中看到这个错误 net.sf.ehcache.constructs.nonstop.NonStopCacheException: keySet timed out at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut
net.sf.ehcache.constructs.nonstop.NonStopCacheException: keySet timed out
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:103)
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:96)
at net.sf.ehcache.constructs.nonstop.store.ExecutorServiceStore.executeClusterOperation(ExecutorServiceStore.java:1187)
at net.sf.ehcache.constructs.nonstop.store.NonstopStoreImpl.executeClusterOperation(NonstopStoreImpl.java:704)
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator.<init>(NonStopCacheKeySet.java:96)
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet.iterator(NonStopCacheKeySet.java:56)
at net.sf.ehcache.Cache.getKeysWithExpiryCheck(v.java:1906)
...
net.sf.ehcache.constructs.nonstop.NonStopCacheException:键集超时
在net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:103)
在net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:96)
位于net.sf.ehcache.constructs.nonstop.store.ExecutorServiceStore.ExecuteClusterRoperation(ExecutorServiceStore.java:1187)
在net.sf.ehcache.constructs.nonstop.store.NonstopStoreImpl.executeClusterRoperation(NonstopStoreImpl.java:704)
在net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator.(NonStopCacheKeySet.java:96)
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet.iterator(NonStopCacheKeySet.java:56)
位于net.sf.ehcache.Cache.getKeysWithExpiryCheck(v.java:1906)
...
上面说:“考虑您的使用是否需要检查过期的密钥。因为此方法需要很长时间,具体取决于缓存设置,…”
因此,我不确定ecache.xml中的超时值增加到什么程度才能停止此错误,尽管20000毫秒对我来说似乎已经足够了,因为文档还提到,每1000个条目所花费的时间大约为200毫秒
这是使用的ehcache.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="RelianceCache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
<cache name="READ_USERS_CACHE" maxElementsInMemory="0" eternal="true" overflowToDisk="false">
<terracotta clustered="true" valueMode="serialization" consistency="strong">
<nonstop immediateTimeout="false" timeoutMillis="20000">
<timeoutBehavior type="exception" />
</nonstop>
</terracotta>
</cache>
<terracottaConfig url="TSA_SERVERS:TSA_PORT" rejoin="true" />
</ehcache>
编辑:
请参阅,在方法
NonStopCacheKeySetIterator
中引发了错误。增加超时不会解决问题。20秒100个条目是非常长的
如果从应用逻辑的观点来看是合适的,我会考虑将超时行为改为<代码> TimeOutSturvie=“LoalRead StestExpEngOnDrand”< /C>。请注意,
localCacheEnabled
属性必须为TRUE,这是默认值
...
<terracotta clustered="true" localCacheEnabled="true" valueMode="serialization" consistency="strong">
<nonstop immediateTimeout="false" timeoutMillis="20000">
<timeoutBehavior type="localReadsAndExceptionOnWrite" />
</nonstop>
</terracotta>
...
。。。
...
另一种解决方案是将一致性更改为默认值
consistency=“finally”
。这很可能会解决问题,但可能会导致缓存返回暂时过时的数据
如文档所述,“考虑您的使用是否需要检查过期密钥…”。是否可以将应用程序逻辑调整为使用Cache.getKey()而不是通过键列表进行迭代?增加超时不会解决问题。20秒100个条目是非常长的
如果从应用逻辑的观点来看是合适的,我会考虑将超时行为改为<代码> TimeOutSturvie=“LoalRead StestExpEngOnDrand”< /C>。请注意,
localCacheEnabled
属性必须为TRUE,这是默认值
...
<terracotta clustered="true" localCacheEnabled="true" valueMode="serialization" consistency="strong">
<nonstop immediateTimeout="false" timeoutMillis="20000">
<timeoutBehavior type="localReadsAndExceptionOnWrite" />
</nonstop>
</terracotta>
...
。。。
...
另一种解决方案是将一致性更改为默认值
consistency=“finally”
。这很可能会解决问题,但可能会导致缓存返回暂时过时的数据
如文档所述,“考虑您的使用是否需要检查过期密钥…”。是否可以调整应用程序逻辑以使用Cache.getKey()而不是通过键列表进行迭代?发生这种情况时,您能否提供有关缓存大小的信息?与Terracotta服务器的启动相比,您的应用程序的生命周期如何?此缓存包含已登录的用户,因此我可以保证大小小于100个条目。与Terracotta服务器相比,我不太清楚你所说的我的应用程序的生命周期是什么意思。我在ehcache-core-2.6.8.jar中添加了一些调试消息,因为原始异常原因已丢失。关于生命周期:你的应用程序是否有可能在Terracotta服务器启动之前尝试访问群集缓存?嗯,不是在这种情况下,Terracotta服务器确实在运行,问题并不总是发生,这意味着有时用户会收到此错误,而大多数情况下不会。发生这种情况时,您能否提供有关缓存大小的信息?与Terracotta服务器的启动相比,您的应用程序的生命周期如何?此缓存包含已登录的用户,因此我可以保证大小小于100个条目。与Terracotta服务器相比,我不太清楚你所说的我的应用程序的生命周期是什么意思。我在ehcache-core-2.6.8.jar中添加了一些调试消息,因为原始异常原因已丢失。关于生命周期:你的应用程序是否有可能在Terracotta服务器启动之前尝试访问群集缓存?嗯,在这种情况下,Terracotta服务器肯定在运行,问题并不总是发生,这意味着用户有时会出现此错误,而大多数情况下不会。