
您好,很高兴为您解答。
先将ehcache-1.4.1.jar、commons-logging-1.0.4.jar、backport-util-concurrent-3.1.jar拷贝到一个指定目录(ehcache-1.4.1.jar依赖commons-logging-1.0.4.jar和backport-util-concurrent-3.1.jar,所以一并加入),这里拷贝到WL_HOME目录(通常为C:/bea/weblogic81)
然后在启动脚本startWebLogic.cmd的CLASSPATH的最前面加上ehcache。即将sete/lib/rt.jar%WL_HOME%/server/lib/webservices.jar%CLASSPATH%
修改为
set CLASSPATH=%WL_HOME%/commons-logging-1.0.4.jar%WL_HOME%/backport-util-concurrent-3.1.jar%WL_HOME%/ehcache-1.4.1.jar%WEBLOGIC_CLASSPATH%%POINTBASE_CLASSPATH%%JAVA_HOME%/jre/lib/rt.jar%WL_HOME%/server/lib/webservices.jar%CLASSPATH%
配置好了环境,接下来配置ehcache的配置文件
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="ehcache.xsd">
<diskStore path="java.io.tmpdir/cacheweb" />
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" />
<defaultCache maxElementsInMemory="3" eternal="false"
timeToIdleSeconds="1" timeToLiveSeconds="1" overflowToDisk="false"
memoryStoreEvictionPolicy="LRU" />
<cache name="userCache" maxElementsInMemory="1000" eternal="true"
overflowToDisk="true" timeToIdleSeconds="60" timeToLiveSeconds="120"
memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
</cache>
</ehcache>
再接下来就是如何使用ehcache了,下面代码为从一个控制用户同一时间只能有一个session的程序中摘出
static CacheManager manager = new CacheManager(SingleUserSessionListener.class.getResourceAsStream("/ehcache.xml"))
public static Cache cache = manager.getCache("userCache")
private void removeUser(HttpSessionBindingEvent e) {
if (e.getName().equals("loginUserCode")) {
cache.remove(e.getValue().toString())
}
}
private void checkUser(HttpSessionBindingEvent e) {
if (e.getName().equals("loginUserCode")) {
String userCode = e.getValue().toString()
if (cache.isElementInMemory(userCode)) {
String sid = cache.get(userCode).getValue().toString()
cache.remove(userCode)
System.out.println("踢出用户" + userCode + ",其sessionId=" + sid)
}
Element el = new Element(userCode, e.getSession().getId())
cache.put(el)
}
}
关于如何使用EhCache,可以参考文章网络文章《细谈Ehcache页面缓存的使用》
看看EhCache的源代码,它的Filter写得一般般(如GzipFilter),比较耗内存。
如若满意,请点击右侧【采纳答案】,如若还有问题,请点击【追问】
希望我的回答对您有所帮助,望采纳!
~ O(∩_∩)O~
设置方法有两种:
一、在../domain/startWebLoigc.***文件中设置
在startWebLogic.bat或startWebLogic.sh中找到以下内容,在其下方添加需要设置的内存
echo ***************************************************
echo * To start WebLogic Server, use a username and *
echo * password assigned to an admin-level user. For *
echo * server administration, use the WebLogic Server *
echo * console at http://[hostname]:[port]/console *
echo ***************************************************
(1)Windows环境:
set MEM_ARGS=-Xms512m -Xmx768m
(2)Linux/Unix环境:
MEM_ARGS="-Xms512m -Xmx768m"
二、在../weblogic81/common/bin/commEnv.***文件中设置在commEnv.bat或commEnv.sh找到以下内容,对其进行修改
(1)Windows环境:
:sun
if "%PRODUCTION_MODE%" == "true" goto sun_prod_mode
set JAVA_VM=-client
set MEM_ARGS=-Xms32m -Xmx200m -XX:MaxPermSize=128m
set JAVA_OPTIONS=%JAVA_OPTIONS% -Xverify:none
goto continue
:sun_prod_mode
set JAVA_VM=-server
set MEM_ARGS=-Xms32m -Xmx200m -XX:MaxPermSize=128m
goto continue
通过修改其中的内存即可,这里选择修改的JDK为sun公司的,weblogic中自带的jrockit JDK修改可以查看:bea中内容。(2)Linux/Unix环境:
Sun)
JAVA_VM=-server
MEM_ARGS="-Xms32m -Xmx200m -XX:MaxPermSize=128m"
和
Sun)
JAVA_VM=-client
MEM_ARGS="-Xms32m -Xmx200m -XX:MaxPermSize=128m"
JAVA_OPTIONS="${JAVA_OPTIONS} -Xverify:none"
通过修改其中的内存即可.欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)