DeadLock when call save in thread and transaction at the same time.
See original GitHub issueDBFlow Version: 4.0.3 Description: Simple way to reproduce the problem like this:
private void testDeadLock() {
final SimpleModule module = new SimpleModule();
module.name = "module1";
module.time = System.currentTimeMillis();
module.save();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Log.d(TAG, "save start");
module.time = System.currentTimeMillis();
module.save();
Log.d(TAG, "save finish");
}
});
thread.start();
FlowManager.getDatabase(SimpleDataBase.class).executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
Log.d(TAG, "save in transaction start");
module.time = System.currentTimeMillis();
module.save();
Log.d(TAG, "save in transaction finish");
}
});
}
Then
07-11 10:35:25.458 4410-4494/? D/MainActivity: save start
07-11 10:35:25.459 4410-4410/? D/MainActivity: save in transaction start
07-11 10:35:55.473 4410-4494/com.example.myapplication W/SQLiteConnectionPool: The connection pool for database '/data/user/0/com.example.myapplication/databases/simple.db' has been unable to grant a connection to thread 2331 (Thread-2) with flags 0x1 for 30.000002 seconds.
Connections: 0 active, 1 idle, 0 available.
07-11 10:36:25.474 4410-4494/com.example.myapplication W/SQLiteConnectionPool: The connection pool for database '/data/user/0/com.example.myapplication/databases/simple.db' has been unable to grant a connection to thread 2331 (Thread-2) with flags 0x1 for 60.001003 seconds.
Connections: 0 active, 1 idle, 0 available.
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Deadlock occuring when multiple threads writing to same ...
So when one first thread got into a transaction and remained idle for than 5 min (minEvicatableTime), it was evicted and its connection...
Read more >How to avoid deadlock when multithreading updates one ...
Multithreading calls the stored procedure at the same time to update data in one table.
Read more >Deadlocks when concurrently inserting using multiple ...
Hi Rick, the issue is that some transactions are sent with a status of pending. Usually, another transaction is sent within seconds where...
Read more >Race conditions and deadlocks - Visual Basic
A deadlock occurs when two threads each lock a different variable at the same time and then try to lock the variable that...
Read more >How to resolve deadlocks in SQL Server
First of all, let's explain the deadlock concept. A deadlock problem occurs when two (or more than two) operations already want to access ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
same thing. transaction more advantageous because you can do more within a transaction and itll overall be more efficient. Like for example:
Will create a transaction for each object and execute them in parallel.
which will do only one transaction for any number of models.
thanks