0

我正在尝试从数据库中获取数据并放入地图并尝试将该地图存储在hazelcast 缓存服务器中。但它给出了错误

com.hazelcast.nio.serialization.HazelcastSerializationException:无法序列化“java.util.TreeMap”。

下面是我的代码。

Map<Integer, List> cacheMap;
cacheMap = (Map<Integer, List>) hazelCastCache.getDataFromCache("CdnToIpConfig", key);

if(cacheMap == null)
{
  LOGGER.info("Cache memory is not allocated");  
  cacheMap = newTreeMap<>(); 
  cdnIpResDto =    configurationService.getCdnIpConfig(pageNo,sortBy,sortingOrder);
  responseDataRange = cdnIpResDto.getDtoList();  
  int lastIndexTracker =0;  
  for (int i = 1; i <= responseDataRange.size(); i++) {
       if (i % 10 == 0) {
            finalData = responseDataRange.subList(i - 10, i);
            cacheMap.put(pageNo, finalData);
            System.out.println(cacheMap);// I can see contents of cacheMap
            pageNo++;
            lastIndexTracker = i;
                   }
               }
   hazelCastCache.addDataToCache("CdnToIpConfig", key, cacheMap); 
   System.out.println("Data added in Hazelcast"); // This line is not getting executed.

由于最后一行打印语句没有被执行,这意味着 TreeMap 没有被添加到缓存中。请帮忙?

4

1 回答 1

0

我面临的问题是在上面的代码中,我采用了一个不实现 Serializable 的子列表。所以我将子列表包装在 ArrayList 中,问题得到了解决。这是修改后的代码:--

finalData = new ArrayList(responseDataRange.subList(i - 10, i));
于 2016-12-26T07:13:47.643 回答