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 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM