超出内存中的XML deserialisation [英] Out of memory during XML deserialisation

查看:106
本文介绍了超出内存中的XML deserialisation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我去 - 我的序列化XML的异步任务。在某些特定情况下,我得到了,而DE-系列化内存错误。我知道有一个所谓的标志 largeHeap ,我可以在我的应用程序中使用。但有什么办法,找出具体避免在那个地方。

按我发现的System.gc()并不可能解决它一个最佳的解决方案。任何人可以帮助我通过它。下面是code段。

 私人的HashMap<字符串,游戏>游戏=新的HashMap<字符串,游戏>();

公共无效负载(LocalDatabaseHelper localDbHelper)抛出异常
{
    同步(gameLockObject){
        GameDetailDAO道=新GameDetailDAO(localDbHelper);

        //这会接我的所有的DATABSE实体
        ArrayList的< GameDetailEntity> dbGameDetails = dao.getEntities(NULL,NULL);

        对于(GameDetailEntity gameDetail:dbGameDetails){
            串gameLevel = gameDetail.getDetailLevel();

            串gameXml = gameDetail.getGameData();

            游戏游戏= NULL;
            如果(gameLevel.equalsIgnoreCase(新手)){
                游戏= Job.deserialiseJob(gameXml,NoviceLevel.class);
            }
            否则,如果(gameLevel.equalsIgnoreCase(专家)){
                游戏= Job.deserialiseJob(gameXml,ExpertLevel.class);
            }

            //设置作业版本
            game.setGameversion(gameDetail.getGameVersion());
            game.setMagicNumber(gameDetail.getMagicNumber());
            game.setInactiveUser(gameDetail.getInactiveUser());
            game.setStartTime(gameDetail.getStartTime());
            game.setFinishTime(gameDetail.getFinishTime());
            game.setGameCompletionTime(gameDetail.getGameCompletionTime());
            如果(!StringUtils.isNullOrEmpty(gameDetail.getGameStatus())){
                game.setGameStatus(GameStatus.valueOf(gameDetail.getGameStatus()));
            }

            //添加作业到店
            games.put(gameDetail.getGameRef()与toLowerCase(Locale.getDefault()),游戏);
        }
    }
}
 

解决方案

我跑,因为原因很简单进入的问题,该字符串的大小是巨大的。巨大。硅简单的解决办法是减少数据正在处理的量。所以,我决定减少字符串的大小。我已经从XML隔离的图像数据,并存储在不同的表中。这减少了需要反序列化的数据量。我单独加载额外的数据。感谢您的答案和你的precious时间。

I am de - serializing my xml in async task. At some particular instance I am getting out of memory error while de- serialization. I know there is a flag called largeHeap which I can use in my application. But is there any way to find out specifically avoid at that place.

As per my finding System.gc() is not probably a best solution to fix it. Can anybody help me through it. Below is the code snippet.

private HashMap<String, Game> games = new HashMap<String, Game>();

public void load(LocalDatabaseHelper localDbHelper) throws Exception
{
    synchronized(gameLockObject) {
        GameDetailDAO dao = new GameDetailDAO(localDbHelper);

        //this will fetch me the all the entities from databse
        ArrayList<GameDetailEntity> dbGameDetails = dao.getEntities(null, null);

        for (GameDetailEntity gameDetail : dbGameDetails) {
            String gameLevel = gameDetail.getDetailLevel();             

            String gameXml = gameDetail.getGameData();

            Game game = null;
            if(gameLevel.equalsIgnoreCase("Novice")) {
                game = Job.deserialiseJob(gameXml, NoviceLevel.class);
            }
            else if (gameLevel.equalsIgnoreCase("Expert")) { 
                game = Job.deserialiseJob(gameXml, ExpertLevel.class);
            }

            //set the job version
            game.setGameversion(gameDetail.getGameVersion());
            game.setMagicNumber(gameDetail.getMagicNumber());
            game.setInactiveUser(gameDetail.getInactiveUser());
            game.setStartTime(gameDetail.getStartTime());
            game.setFinishTime(gameDetail.getFinishTime());
            game.setGameCompletionTime(gameDetail.getGameCompletionTime());
            if (!StringUtils.isNullOrEmpty(gameDetail.getGameStatus())) {
                game.setGameStatus(GameStatus.valueOf(gameDetail.getGameStatus()));
            }

            //add the job to the store
            games.put(gameDetail.getGameRef().toLowerCase(Locale.getDefault()), game);
        }
    }
}

解决方案

I ran into problem because of the simple reason, the size of the string was huge. HUGE. Si simple solution would be reduce the amount of data that is processing. So I decided to reduce the size of the string. I have segregated the image data from the XML and stored in different table. This reduce the amount of data that needed to de-serialize. I reload the extra data separately. Thanks for answers and for your precious time.

这篇关于超出内存中的XML deserialisation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆