IOS Database multithreaded Operations

Source: Internet
Author: User

SQLite is to support multi-threaded operation, the need to initialize the database is to do a thread-safe config, refer to the following links, looks more complex.

Http://www.cnblogs.com/wfwenchao/p/3964213.html

Many iOS projects use Fmdb, a third-party open Source Library, but Fmdb cannot co-fmdatabase objects in multiple threads, because the class itself is not thread-safe, and if such use causes problems such as data confusion.

If you need to operate a database with multiple threads, you need to use Fmdatabasequeue to ensure thread safety.

First the fmdatabasequeue is initialized with a database file address, and then a closure (block) can be passed into the Indatabase method. Operate the database in a closure without directly participating in the management of the fmdatabase.

Fmdatabasequeue to solve this problem is to create a queue, and then put into the queue block sequence execution, so as to avoid multi-threaded simultaneous access to the database;

If it is multi-threaded to create fmdatabasequeue instances, in fact there are multiple queues, or there is a problem of database competition, and the same as when using Fmdatabase;

Let each thread use the same queue instance, the problem is solved successfully;

Reference:

1) http://blog.csdn.net/kyfxbl/article/details/38123239

2) http://blog.devtang.com/blog/2012/04/22/use-fmdb/

IOS Database multithreaded Operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.