SQLite: Multi-threaded Operation database "database is locked" Workaround (ii)

Source: Internet
Author: User

Previous Blog "SQLite: Multi-threaded Operation database" is locked "solution" by registering the delay function to deal with the problem of database lock. This approach solves the problem, but the delay slows the progress when multiple threads write large amounts of data to the database.

Think of method Two:

1. Create a linked list, link the structure of the following format, thread 1, thread 2, thread 3 ... Instead of rewriting the database directly, insert the SQL statement into the linked list;

struct*buf;uint32_t len;} sqlitem_t;

2. create a separate thread, full-time read SQL statements from the linked list, and rewrite the database.

So that only one thread to operate the database, the database is locked the problem can be avoided, the database processing efficiency is greatly improved.

3. use transactions to further improve SQLite processing performance

Ideas are as follows:

Execution "begin TRANSACTION; " statement to execute multiple insert/update/delete/... Statement execution "commit transaction; " statement

SQLite: Multi-threaded Operation database "database is locked" Workaround (ii)

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.