ormlite 批处理操作

简介: 提高ormlite的批处理速度 http://stackoverflow.com/quegoogstions/11761472/ormlites-createorupdate-seems-slow-what-is-normal-speed   This may be the "expected" speed unfortunately.

提高ormlite的批处理速度

http://stackoverflow.com/quegoogstions/11761472/ormlites-createorupdate-seems-slow-what-is-normal-speed

 

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 ORMLite Dao.callBatchTasks(...) method.

In by BulkInsertsTest android unit test, 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<Void>() { 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(...)方法,因为你必须确保你闭上你自己的事务:

 

相关文章
|
4月前
|
SQL Oracle Java
sql文件批处理程序-java桌面应用
sql文件批处理程序-java桌面应用
46 0
|
4月前
|
Kubernetes Java 流计算
Flink application on k8s 有没有和 session 模式通过-C 指定额外的 jar 的相同功能啊?
Flink application on k8s 有没有和 session 模式通过-C 指定额外的 jar 的相同功能啊?
73 0
|
29天前
|
SQL 流计算
Flink SQL 在快手实践问题之Window TVF改进窗口聚合功能如何解决
Flink SQL 在快手实践问题之Window TVF改进窗口聚合功能如何解决
15 1
|
20天前
|
SQL 数据处理 数据库
提升数据处理效率:深入探讨Entity Framework Core中的批量插入与更新操作及其优缺点
【8月更文挑战第31天】在软件开发中,批量插入和更新数据是常见需求。Entity Framework Core 提供了批处理功能,如 `AddRange` 和原生 SQL 更新,以提高效率。本文通过对比这两种方法,详细探讨它们的优缺点及适用场景。
37 0
|
11月前
|
SQL Java Apache
[1.2.0新功能系列:三]Apache doris 1.2.0 Java UDF 函数开发及使用
[1.2.0新功能系列:三]Apache doris 1.2.0 Java UDF 函数开发及使用
171 0
Java8流式操作——中间操作
imit:限制,只取流中前指定位的元素。从前往后数,只取前xxx个元素
|
分布式计算 Java
Java8流式操作——最终操作
当我们通过最终方法对流对象进行操作,说明stream流操作也完成,最后我们将对象汇总成一个结果(总数、对象、集合……)
|
SQL 存储 Java
Java 结构化数据处理开源库SPL,再也不用苦哈哈写SQL了
现代Java应用架构越来越强调数据存储和处理分离,以获得更好的可维护性、可扩展性以及可移植性,比如火热的微服务就是一种典型。
170 0
|
存储 NoSQL Java
Java 操作 kudu-创建表操作 | 学习笔记
快速学习 Java 操作 kudu-创建表操作
307 0
Java 操作 kudu-创建表操作 | 学习笔记
|
存储 算法 NoSQL
Java 操作 kudu--分区策略 | 学习笔记
快速学习 Java 操作 kudu--分区策略
515 0
Java 操作 kudu--分区策略 | 学习笔记