How to Execute threads in parallel and insert corresponding data in sqlite database without database lock?

I need to call multiple api's each executing in separate thread and insert the respective data from response to sqlite database without causing locks. Can anyone help me in this regard with a working example that I can refer to.

Answers


I need to call multiple api's each executing in separate thread and insert the respective data from response to sqlite database without causing locks.

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.


Need Your Help

Why can't I access DateTime->date in PHP's DateTime class? Is it a bug?

php datetime

Using the DateTime class, if I try to run the following code.

Express, node.js and redis: Separated function to access data

node.js express redis

Im trying to create a file 'users.js' where id like to manage all the redis accesses to the users data. In this file i have the next function, where i get the users ive saved in a list, to then loa...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.