Sqlite: multi-threaded database operation "database is locked" solution (2), sqlitelocked

Source: Internet
Author: User

Sqlite: multi-threaded database operation "database is locked" solution (2), sqlitelocked

In the previous blog "sqlite: multi-threaded database operation" database is locked "solution", we registered a latency function to solve the database lock problem. This method can solve the problem, but when multiple threads write a large amount of data to the database, the delay will slow down.

Method 2:

1.Create a linked list and link the struct in the following format: thread 1, thread 2, thread 3... instead of directly rewriting the database, insert SQL statements into the linked list;

Typedef struct {uint8_t * buf; uint32_t len;} sqlItem_t;

2.Create an independent thread to read SQL statements from the linked list and rewrite the database.

In this way, only one thread can operate on the database, and the database can be prevented from being locked, which greatly improves the processing efficiency of the database.

3.Use transactions to further improve sqlite processing performance

The idea is as follows:

Execute the "begin transaction;" statement to execute multiple insert/update/delete/... statements to execute the "commit transaction;" Statement

 


How does SQLite solve database is locked?

Sqlite is a file. A process can be opened and written, but other processes cannot be written. Arrange your multi-process properly.

Hello, database is locked when I insert data to the sqlite database through the input content in the interface when I am working on a project! Ask you

The database process is not closed and released in time after it is opened ......

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.