标准ORMLite方法中的CursorWindowAllocationException [英] CursorWindowAllocationException in standard ORMLite method

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

问题描述

我需要在数据库中保存一些对象。我在我的Dao类中使用了此代码。

I need save some objects in DB. I'm using this code in my Dao class.

  public void saveActions(List<Action> actionList) throws SQLException {
    for (Action action : actionList) {
        createOrUpdate(action);
      }
  }

有时我在 createOrUpdate()函数。

有人可以解决此问题吗?

Does anyone have solution of this problem?

推荐答案

如果您查找 CursorWindowAllocationException 的来源,则会显示为:

If you look up the source of CursorWindowAllocationException it reads:


当无法分配CursorWindow时抛出此异常,
最有可能是由于内存不可用。

This exception is thrown when a CursorWindow couldn't be allocated, most probably due to memory not being available.

如果您遵循堆栈,您将看到调用 com.j256.ormlite.android.AndroidDatabaseConnection.queryForLong 为每个 createOrUpdate 调用。

If you follow the stack, you'll see that the call com.j256.ormlite.android.AndroidDatabaseConnection.queryForLong is creating a cursor for every createOrUpdate call.

所以这里可能发生的事情是,光标太多了在释放内存之前创建。

So what's likely happening here is that there are too many Cursors being created before the memory is freed.

您应在交易,或者更好的方法是,使用批处理任务。例如,

You should execute these calls in a transaction, or better yet, use batch tasks. E.g.

actionDao.callBatchTasks(new Callable<Void>() {
        public Void call() throws SQLException {
            for (Action action : actionList) {
                actionDao.createOrUpdate(action);
            }
        return null;
    }
});

这篇关于标准ORMLite方法中的CursorWindowAllocationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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