What care i need to take when my 2 different thread access same database ?
-
i have one foreground thread access on sqlite database and background thread access same database. so in this type of situation what steps i need to take to avoid device getting slow, hang issue.
-
@jsulm Can you suggest efficient way for many queries. i have to improve this inefficient design to make it efficient. So Please suggest me how to do it ?
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
Can you suggest efficient way for many queries
Simply open the connection once and use it for your queries. Close the connection when the app is closed.
-
i have one foreground thread access on sqlite database and background thread access same database. so in this type of situation what steps i need to take to avoid device getting slow, hang issue.
@Qt-embedded-developer
from sqlite.orgMulti-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.
-
@Qt-embedded-developer
from sqlite.orgMulti-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.
@J-Hilk said in What care i need to take when my 2 different thread access same database ?:
SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.
I want elaboration of this statement
" SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads."
If meaning of this statement is " i can not use same database connection in multiple thread" then How to make it simultaneously access ?
-
@J-Hilk said in What care i need to take when my 2 different thread access same database ?:
SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.
I want elaboration of this statement
" SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads."
If meaning of this statement is " i can not use same database connection in multiple thread" then How to make it simultaneously access ?
@Qt-embedded-developer
I want an elaboration on how you made your database connections so far -
@Qt-embedded-developer
I want an elaboration on how you made your database connections so far@J-Hilk i am opening database and closing database when i want to execute sqlite query
-
@J-Hilk said in What care i need to take when my 2 different thread access same database ?:
SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.
I want elaboration of this statement
" SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads."
If meaning of this statement is " i can not use same database connection in multiple thread" then How to make it simultaneously access ?
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
then How to make it simultaneously access
Create one connection in each thread...
-
@J-Hilk i am opening database and closing database when i want to execute sqlite query
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
i am opening database and closing database when i want to execute sqlite query
Quite inefficient if you execute many queries
-
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
i am opening database and closing database when i want to execute sqlite query
Quite inefficient if you execute many queries
@jsulm Can you suggest efficient way for many queries. i have to improve this inefficient design to make it efficient. So Please suggest me how to do it ?
-
@jsulm Can you suggest efficient way for many queries. i have to improve this inefficient design to make it efficient. So Please suggest me how to do it ?
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
Can you suggest efficient way for many queries
Simply open the connection once and use it for your queries. Close the connection when the app is closed.
-
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
Can you suggest efficient way for many queries
Simply open the connection once and use it for your queries. Close the connection when the app is closed.
@jsulm but this is the problem " no single database connection is used simultaneously in two or more threads" so i need to close the connection and open connection for simultaneous access.
So what is other efficient solution to tackle this issue ?
-
How to know which thread handler open the data base in foreground thread and background thread ?
-
@jsulm but this is the problem " no single database connection is used simultaneously in two or more threads" so i need to close the connection and open connection for simultaneous access.
So what is other efficient solution to tackle this issue ?
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
but this is the problem
No, it's not.
I already wrote before: Create one connection in each thread. -
https://sqlite.org/threadsafe.html
It sounds like sqlite is in mode 2. So internally sqlite is using mutexes. -
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
Can you suggest efficient way for many queries
Simply open the connection once and use it for your queries. Close the connection when the app is closed.
@jsulm i have opened the database connection and not close it . but it make my ui stuck to wait for release mutex lock
-
@jsulm i have opened the database connection and not close it . but it make my ui stuck to wait for release mutex lock
@Qt-embedded-developer said in What care i need to take when my 2 different thread access same database ?:
but it make my ui stuck to wait for release mutex lock
Well, then analyse and fix your code - you have a dead-lock