gpt4 book ai didi

android - 在 SQLite 中使用事务在 JellyBean 中给出错误

转载 作者:行者123 更新时间:2023-12-02 07:14:39 24 4
gpt4 key购买 nike

我有一个 DownLoadData 类,它扩展了异步任务,用于从 Web 服务下载主数据。 SQLite 数据库中有 10 个主表,每个表都需要单独的 Web 服务调用。因此,在 DownloadData 任务中,我有 10 个线程。每个都会调用各自的 Web 服务,接收数据,然后将其插入到各自的表中。

我在 _onPreExecute()_ 处启动事务,并在检查所有线程是否已完成后,在 _onPostExecute()_ 处结束事务。

问题是,这种方法对于 ICS 之前的版本非常有效。它似乎在 JellyBean 中不起作用。该应用程序每 60 秒就会挂起并显示此 logcat 消息:

04-02 14:53:23.263: W/SQLiteConnectionPool(1409): The connection pool for database '/data/data/com.c2info.liveorder/databases/DB' has been unable to grant a connection to thread 117 (AsyncTask #2) with flags 0x1 for 30.010002 seconds.

04-02 14:53:23.263: W/SQLiteConnectionPool(1409): Connections: 0 active, 1 idle, 0 available.

我像这样开始和结束交易:

public LocalDatabase beginTransact() {

mdbHelper = new DatabaseHelper(ctx);
mdb = mdbHelper.getWritableDatabase();
execSQL("BEGIN");
return this;
}

public void endTransact() {

execSQL("END");
mdbHelper.close();
}

我还在所有线程中使用相同的数据库实例。

最佳答案

我通过将每个单独的线程视为单个事务而不是所有线程的单个事务来克服 JellyBean 中的问题

关于android - 在 SQLite 中使用事务在 JellyBean 中给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15761340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com