标准ORMLite方法中的CursorWindowAllocationException [英] CursorWindowAllocationException in standard ORMLite method
问题描述
我需要在数据库中保存一些对象。我在我的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屋!