gpt4 book ai didi

java - 并行部署的 web 应用程序的所有版本的缓存都已关闭

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:55:38 28 4
gpt4 key购买 nike

我在版本为 deployed in parallel 的网络应用程序中使用 ehcache在 Tomcat 实例上。这是在不停止应用程序的情况下部署新版本的便捷方法。

然而,我对这种继续进行的方式有一个问题:即使我给缓存和磁盘存储不同的名称,根据 webapp 的版本,所有缓存在停止时停止 一个实例。

我的配置是:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" name="mywebapp-${project.version}_build_${buildNumber}">
<defaultCache
maxElementsInMemory="1000"
maxElementsOnDisk="10000"
eternal="false"
timeToLiveSeconds="300"
timeToIdleSeconds="300"
overflowToDisk="true"
diskPersistent="false"
memoryStoreEvictionPolicy="LRU"
statistics="true"
/>

<cache
maxElementsInMemory="1000"
maxElementsOnDisk="10000"
name="org.hibernate.cache.internal.StandardQueryCache"
eternal="false"
timeToLiveSeconds="300"
timeToIdleSeconds="300"
overflowToDisk="true"
diskPersistent="false"
statistics="true"/>

<cache
name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000"
maxElementsOnDisk="100000"
timeToLiveSeconds="300"
timeToIdleSeconds="300"
eternal="false"
overflowToDisk="true"
diskPersistent="false"
statistics="true"/>

<cache
name="query.Presences"
maxElementsInMemory="100"
maxElementsOnDisk="1000"
eternal="false"
timeToLiveSeconds="300"
timeToIdleSeconds="300"
overflowToDisk="true"
diskPersistent="false"
statistics="true"/>

<diskStore path="java.io.tmpdir/mywebapp-${project.version}_build_${buildNumber}"/>

</ehcache>

${project.version}${buildNumber}

在构建过程中被 maven 替换。

有人知道如何避免这种不良行为吗?

我正在使用 ehcache-core-2.4.3 和 hibernate-ehcache-4.3.8。

最佳答案

net.sf.ehcache.constructs.web.ShutdownListener 的工作方式是关闭所有 缓存管理器。

因此,唯一适合您的方法是确保您的缓存管理器最终位于不同的类加载器中,即 ehcache 由 Web 应用程序类加载器而不是容器类加载器加载。

您是否在应用程序的 WEB-INF/lib 中提供了 ehcache jar?如果是,你确定tomcat的类路径中没有Ehcache吗?

如果此解决方案仍然无效,您最好创建自己的 ServletContextListener,它只会从包含应用程序中关闭缓存管理器。

关于java - 并行部署的 web 应用程序的所有版本的缓存都已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30938890/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com