question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeadLock when call save in thread and transaction at the same time.

See original GitHub issue

DBFlow 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:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
agrosnercommented, Jul 13, 2017

same thing. transaction more advantageous because you can do more within a transaction and itll overall be more efficient. Like for example:

list.forEach { it.async().save() }

Will create a transaction for each object and execute them in parallel.


FlowManager.getDatabase(MyDatabase::class.java).beginTransactionAsync { db ->
  list.forEach { it.save(db) }
}.build().execute()

which will do only one transaction for any number of models.

0reactions
olbbcommented, Jul 17, 2017

thanks

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found