iteye_12241 2012-04-20 11:56
浏览 975
已采纳

关于ehcache处理大数据的问题

我运行后,出现如下错误:
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类型,其余的两个cache为String类型。
上面那个错误什么原因啊,如何改正?谢谢啦~

[code="java"]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();        
}

}
[/code]

ehcache的配置文件为:
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
xsi:noNamespaceSchemaLocation="ehcache.xsd">

maxElementsInMemory="10000"
maxElementsOnDisk="1000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
maxEntriesLocalHeap="10000"
maxEntriesLocalDisk="10000000"
/>

[/code]

  • 写回答

1条回答 默认 最新

  • iteye_3843 2012-04-20 12:38
    关注

    加diskPersistent="true"试试

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多