我运行后,出现如下错误:
2012-4-20 11:51:43 net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask call
严重: Disk Write of 4 failed:
java.io.NotSerializableException: java.util.RandomAccessSubList
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteObject(Unknown Source)
at net.sf.ehcache.Element.writeObject(Element.java:797)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97)
at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:413)
at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:392)
at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:493)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1154)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1138)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
相关的cache管理类代码如下:
其中licensesCache中存放的数据中value为List<String>类型,其余的两个cache为String类型。
上面那个错误什么原因啊,如何改正?谢谢啦~
package com.traffic.cache;
import java.util.List;
import java.util.Timer;
import com.traffic.protocol.LicenseProtocol;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class LicenseCacheManager {
private static CacheManager cacheManager = null;
private static Cache blackListCache = null;
private static Cache whiteListCache = null;
private static Cache licensesCache = null;
private static Timer timer = null;
static {
cacheManager = CacheManager.create("src/config/ehcache.xml");
cacheManager.addCache("blackListCache");
cacheManager.addCache("whiteListCache");
cacheManager.addCache("licensesCache");
licensesCache = cacheManager.getCache("licensesCache");
blackListCache = cacheManager.getCache("blackListCache");
whiteListCache = cacheManager.getCache("whiteListCache");
// 启动定时器,每隔30分钟执行清理缓存任务
timer = new Timer();
timer.scheduleAtFixedRate(new ClearCacheTask(), 300000, 300000);
}
public static void addLicense(int number, List<String> licenses){
licensesCache.put(new Element(number, licenses));
}
public static List<String> getLicenses(int number) {
Element e = licensesCache.removeAndReturnElement(number);
List<String> l =(List<String>)e.getObjectValue();
return l;
}
public static boolean haveLicenses() {
if(licensesCache.getSize() == 0) {
return false;
}
return true;
}
public static void addBlackList(String license) {
Element e = new Element(license, "blackList");
blackListCache.put(e);
}
public static void addWhiteList(String license) {
Element e = new Element(license, "whiteList");
whiteListCache.put(e);
}
// 根据type制定的类型,添加到相应的cache
public static void addItem(String type, String license) {
if(type.equals(LicenseProtocol.WhiteLicenseType)) {
addWhiteList(license);
} else if(type.equals(LicenseProtocol.BlackLicenseType)){
addBlackList(license);
}
}
public static boolean isInBlackList(String license) {
if(blackListCache.isElementInMemory(license)) {
return true;
}
return false;
}
public static boolean isInWhiteList(String license) {
if(whiteListCache.isElementInMemory(license)) {
return true;
}
return false;
}
public static Cache getBlackListCache() {
return blackListCache;
}
public static Cache getWhiteListCache() {
return whiteListCache;
}
public static CacheManager getCacheManager() {
return cacheManager;
}
public static void clear() {
blackListCache.removeAll();
whiteListCache.removeAll();
}
public static void closeManager() {
timer.cancel();
blackListCache.dispose();
whiteListCache.dispose();
cacheManager.shutdown();
}
}
ehcache的配置文件为:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd">
<diskStore path="D:/cache" />
<defaultCache
maxElementsInMemory="10000"
maxElementsOnDisk="1000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
maxEntriesLocalHeap="10000"
maxEntriesLocalDisk="10000000"
/>
</ehcache>
相关推荐
1.解压缩到目录下,复制ehcache-monitor-kit-1.0.0\lib\ehcache-probe-1.0.0.jar包到application的web-inf/lib目录下 2.将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名...
ehcache3-samples, 关于使用 Ehcache 3,一些示例/教程 Ehcache示例这里知识库包含有关 Ehcache 3用法的示例和教程。示例'basic'演示 Ehcache 3的基本配置和用法'集群'- 演示如何在Terracotta服务器上使用分布式缓存...
它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个 gzip 缓存 servlet 过滤器,支持 REST 和 SOAP api 等特点。 优点: 1)快速 2)简单 3)多种缓存策略 4)缓存数据有两级:内存和磁盘...
hibernate+ehcache hibernate+ehcache hibernate+ehcache hibernate+ehcache hibernate+ehcache
ehcache-3.8.1.jar
ehcache集群同步配置实例加说明文档
它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点。 Ehcache最初是由Greg Luck于2003年开始开发。2009年,该项目被Terracotta购买。软件仍然是开源,...
EhCache
赠送jar包:ehcache-3.9.9.jar; 赠送原API文档:ehcache-3.9.9-javadoc.jar; 赠送源代码:ehcache-3.9.9-sources.jar; 赠送Maven依赖信息文件:ehcache-3.9.9.pom; 包含翻译后的API文档:ehcache-3.9.9-javadoc-...
hibernate ehcache.xml 配置详解
ehcache所需的ehcache-core-2.5.2.jar及其源码ehcache-core-2.5.2-sources.jar
spring3整合EhCache注解实例
一个ehcache的简单示例,我只是留个备份,你们想要可以私聊我
ehcache所需jar包 cglib-nodep-2.2.jar ehcache-core-2.5.2.jar ehcache-spring-annotations-1.2.0.jar guava-13.0.1.jar ehcache-terracotta-2.5.2.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar terracotta-...
软件介绍: 已测试有效的ehcache.xsd文件,引入ide中,进行ehcache.xml的代码提示。Windows外壳公用DLL文件,大小23.1KB。
赠送jar包:ehcache-3.3.1.jar; 赠送原API文档:ehcache-3.3.1-javadoc.jar; 赠送源代码:ehcache-3.3.1-sources.jar; 赠送Maven依赖信息文件:ehcache-3.3.1.pom; 包含翻译后的API文档:ehcache-3.3.1-javadoc-...
ehcache资料(包含ehcache jar包)
ehcache-core-2.6.10.jar依赖包 MyBatiesEhCache二级缓存 Ehcache是一种广泛使用的开源Java分布式...它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点
具有集群支持的 Ehcache 3(ehcache-clustered-3.8.1-kit.zip)
它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点。 Ehcache最初是由Greg Luck于2003年开始开发。2009年,该项目被Terracotta购买。软件仍然是开源,...