博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ormlite 批处理操作
阅读量:6173 次
发布时间:2019-06-21

本文共 1443 字,大约阅读时间需要 4 分钟。

提高ormlite的批处理速度

 

This may be the "expected" speed unfortunately. Make sure you are using ORMLite version 4.39 or higher. createOrUpdate(...) was using a more expensive method to test for existing of the object in the database beforehand. But I suspect this is going to be a minimal speed improvement.

If I create 100 new rows then the speed is even slower.

By default Sqlite is in auto-commit mode. One thing to try is to wrap your inserts (or your createOrUpdates) using the the  Dao.callBatchTasks(...) method.

In by , the following doInserts(...) method inserts 1000 items. When I just call it:

doInserts(dao);

It takes 7.3 seconds in my emulator. If I call using the callBatchTasks(...) method which wraps a transactions around the call in Android Sqlite:

dao.callBatchTasks(new Callable
() { public Void call() throws Exception { doInserts(dao); return null; } });

It takes 1.6 seconds. The same performance can be had by using the dao.setSavePoint(...)method. This starts a transaction but is not as good as the callBachTasks(...) method because you have to make sure you close your own transaction:

DatabaseConnection conn = dao.startThreadConnection(); Savepoint savePoint = null; try { savePoint = conn.setSavePoint(null); doInserts(dao); } finally { // commit at the end conn.commit(savePoint); dao.endThreadConnection(conn); }

This also takes ~1.7 seconds.

 

 dao.setsavePoint开始一个事务,但不如callBachTasks(...)方法,因为你必须确保你闭上你自己的事务:

 

转载地址:http://rxmba.baihongyu.com/

你可能感兴趣的文章
Ubuntu 18.04.1 LTS下部署FastDFS 5.11+Nginx 1.14.0
查看>>
PHP 运行方式(PHP SAPI介绍)
查看>>
puppet学习之puppet证书验证
查看>>
Server 2008 R2 AD RMS完整部署:四、客户端篇
查看>>
Alcatel-Lucent 7750 运营商认证设备在线用户数OID
查看>>
靠自己。linux manul手册入门
查看>>
思科设备中查询筛选的命令精华
查看>>
大数据未来将呈现的八大发展趋势
查看>>
cm 升级
查看>>
创建数据库快照并恢复数据
查看>>
我的友情链接
查看>>
APP抓包——Fiddler工具
查看>>
java 图片处理
查看>>
博主制作的开源JAVA WEB游戏-《天命.罗生门》
查看>>
Windows软链脚本
查看>>
IOS开发之异步加载网络图片并缓存本地实现瀑布流(二)
查看>>
足球赛事球员信息api
查看>>
那些年我们经历过的运维
查看>>
安装带有调试信息的C库
查看>>
迷宫的基本实现
查看>>