如何执行并行线程

如何执行并行线程

本文介绍了如何执行并行线程,并没有插入数据库锁相应的SQLite数据库的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用多个API在单独的线程执行的每个并不会造成锁插入来自回应SQLite数据库相应的数据。谁能帮我在这方面有一个工作的例子,我可以参考一下。


解决方案

You don't need to do anything special. Multiple threads can make use of the same SQLiteDatabase object without you doing locking at the application level. Sqlite does it's own locking under the covers. You should never get deadlocks but one thread will have to wait for the other thread to finish making its insert.

See these questions/answers:

Sqlite under Android is single threaded. Even if multiple threads were using the same database connection, my understanding is that they would be blocked from running concurrently. There is no way to get around this limitation. If you open two connections to the same database, this would corrupt the database because database updates would not be coordinated.

这篇关于如何执行并行线程,并没有插入数据库锁相应的SQLite数据库的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 19:35