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 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的