我们正在Solaris上运行一个Spring3.0.5Web应用程序,在Solaris上使用WebLogic服务器10.3.4,使用Sun 1.6.0_x 64位,使用EhCache 2.4.2作为缓存库。WLS被设置为具有两个节点的集群,它们都运行在同一台物理机器上,都是通过标准的startManagedWebLogic.sh脚本启动的(不使用NodeManager /管理控制台)。
在我们的ehcache.xml中,我们设置了如下所示的磁盘存储路径:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<!-- Location of persistent caches on disk -->
<diskStore path="ehcache.disk.store.dir" />
..根据the 2.4 series documentation of EhCache,此设置允许设置JVM系统属性,以指定磁盘存储路径。
使用标准的startManagedWebLogic.sh元素在JAVA_OPTIONS中设置系统属性:
JAVA_OPTIONS="-Dehcache.disk.store.dir=/var/tmp/EhCache-${SERVER_NAME} <other stuff>"
export JAVA_OPTIONS在这些选项之前,在相同的脚本中定义SERVER_NAME。
在启动群集节点期间,我可以看到正确设置的属性(为更好的可读性而包装):
/usr/jdk/jdk1.6.0_21/bin/java -d64 -server -Xms4096m -Xmx4096m
-XX:PermSize=512m -XX:MaxPermSize=512m -XX:+UseParallelOldGC
-verbose:gc -XX:+PrintGCTimeStamps -Dweblogic.Name=Node2 [..]
-Dehcache.disk.store.dir=/var/tmp/EhCache-Node2 [..]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
weblogic.Server但是,使用应用程序,我可以看到占位符没有被正确替换,因此使用占位符名称而不是实际路径设置:
2012-08-22 11:52:59,426 DEBUG [net.sf.ehcache.CacheManager] - [Creating new CacheManager with default config]
2012-08-22 11:52:59,429 DEBUG [net.sf.ehcache.CacheManager] - [Configuring ehcache from classpath.]
..
2012-08-22 11:52:59,458 DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] - [Disk Store Path: ehcache.disk.store.dir]
..
2012-08-22 11:52:59,586 DEBUG [net.sf.ehcache.store.DiskStore] - [IOException reading index. Creating new index. ]
2012-08-22 11:52:59,587 DEBUG [net.sf.ehcache.store.DiskStore] - [Index file ehcache.disk.store.dir/bookmarksCountForUserCache.index deleted.]
2012-08-22 11:52:59,588 DEBUG [net.sf.ehcache.store.DiskStore] - [Index file ehcache.disk.store.dir/bookmarksCountForUserCache.index created successfully]
2012-08-22 11:52:59,588 DEBUG [net.sf.ehcache.store.DiskStore] - [Index file dirty or empty. Deleting data file bookmarksCountForUserCache.data]
2012-08-22 11:52:59,597 DEBUG [net.sf.ehcache.store.MemoryStore] - [Initialized net.sf.ehcache.store.LruMemoryStore for bookmarksCountForUserCache]
2012-08-22 11:52:59,600 DEBUG [net.sf.ehcache.store.LruMemoryStore] - [bookmarksCountForUserCache Cache: Using SpoolingLinkedHashMap implementation]
2012-08-22 11:52:59,601 DEBUG [net.sf.ehcache.Cache] - [Initialised cache: bookmarksCountForUserCache]在我的WLS域中的文件系统中,我可以看到创建了一个新文件夹ehcache.disk.store.dir,因此路径被解释为相对路径。
我没有使用普通字符串ehcache.disk.store.dir,而是尝试使用标准模式${ehcache.disk.store.dir},但这只更改了要用${..}创建的文件夹名。
是否有一种方法可以使用系统属性和所有节点的相同EhCache配置指定每个节点的磁盘存储路径?
我们的ehcache.xml位于已部署的.war文件中,因此对于所有集群节点都是相同的。更改应用程序代码不是一种选择,因为我们已经过去冻结了这个版本的代码。但是,如上文所述,我可以调整服务器的启动设置以设置系统属性。
谢谢你的帮助!
发布于 2012-09-06 17:45:46
不幸的是,我们未能找出这种行为的原因。
作为解决办法,我们通过在diskStore中注释ehcache.xml元素完全禁用了磁盘存储。
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<!-- Location of persistent caches on disk
<diskStore path="ehcache.disk.store.dir" />
-->
..并将所有缓存的属性overflowToDisk和diskPersistent设置为false。
发布于 2012-10-25 13:38:15
使用-Dehcache.disk.store.dir系统属性应该仍然有效。
通过hibernate配置设置属性也有问题。
发布于 2014-01-17 01:22:19
你试过-Djava.io.tmpdir=/var/tmp/EhCache-${SERVER_NAME}?吗?
https://stackoverflow.com/questions/12087935
复制相似问题