Android 连接池无法授予线程连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11742464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connection pool has been unable to grant a connection to thread
提问by Basic Coder
I'm using GreenDAO for database handling in Android. When performing many database changes (> 15.000) I get this error Message:
我在 Android 中使用 GreenDAO 进行数据库处理。执行许多数据库更改 (> 15.000) 时,我收到此错误消息:
The connection pool for database '/data/data/...' has been unable to grant a connection to thread 312 (Thread-312) with flags 0x1 for 30.000002 seconds.
数据库“/data/data/...”的连接池在 30.000002 秒内无法授予与标志为 0x1 的线程 312 (Thread-312) 的连接。
Everything gets stuck. Why does this error happen?
一切都卡住了。为什么会发生这个错误?
采纳答案by Kaediil
I can't say for sure about this particular implementation, but there is a connectionpool usually backing a ORM. The connection pool opens a set number of connections to the database and recycles them as you close them and open new connections. What that error is telling you is that it probably hit a limit. That can happen for a large variety of reasons, one is that possibly there is some deadlock in the DB because you are updating two tables and two different transactions are holding different tables waiting for the other to release. Or simply that there are just too many open connections and the DB or connection pool just gets confused.
我不能肯定这个特定的实现,但是有一个通常支持 ORM 的连接池。连接池打开一定数量的数据库连接,并在您关闭它们和打开新连接时回收它们。该错误告诉您的是它可能达到了限制。发生这种情况的原因有很多,一个是数据库中可能存在一些死锁,因为您正在更新两个表并且两个不同的事务持有不同的表,等待另一个释放。或者只是因为打开的连接太多而数据库或连接池会变得混乱。
Sorry that is not really an answer, but you are going to need to look at the docs for GreenDAO to see how this might happen.
抱歉,这不是真正的答案,但您需要查看 GreenDAO 的文档以了解这是如何发生的。
回答by hkutluay
I got this message when I want to select a query on a table which is used on a transaction without ended transaction before. Problem solved after executing endTransaction()
on finally block of transaction.
当我想在之前没有结束事务的事务中使用的表上选择查询时收到此消息。endTransaction()
在 finally 事务块上执行后问题解决。
回答by Blaze Gawlik
I got this message when creating too many connections to SQLite via DBFlow FlowQueryList . My solution was to make sure that once you were done with the query list to call endTransactionAndNotify()
and then close()
on the querylist.
我在通过 DBFlow FlowQueryList 创建了太多到 SQLite 的连接时收到了这条消息。我的解决方案是确保一旦您完成了要调用的查询列表endTransactionAndNotify()
,然后再调用查询列表close()
。
Calling endTransactionAndNotify()
alone did not do the trick.
I hope this helps, this thread certainly helped me.
endTransactionAndNotify()
单独打电话并不能解决问题。我希望这有帮助,这个线程肯定对我有帮助。