多个连接的SQLite同声异步任务 [英] Multiple connections to SQLite with simultaneous async Tasks

查看:153
本文介绍了多个连接的SQLite同声异步任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的情况有Sync_Class的同步操作,在后台AsyncTasks,从我的应用程序到我的服务器。
每次我的应用程序一个动作需要将数据从我SQLite的改变,因为首先我的应用程序时更新我的​​本地数据库作为第二个步骤在后台抛出的AsyncTask到我的服务器启动同步。在案件的80%,我的应用程序的伟大工程,但案件的另外20%会抛出一个IllegalStateException异常,因为应用程序尝试重新打开连接或打开关闭的连接,当我必须在6个线条更上方打开数据库的方法。在这种情况下,我认为这个问题是在数据库中的多个访问非常同时,我是正确的?

In my scenario it has Sync_Class that syncs, with AsyncTasks in background , from my app to my server. Every time that my app does one action that need to change data from my SQLite, as first step my app updates my local database as second step throws a AsyncTask in background to start the sync with my server. In the 80% of cases my app works great but the other 20% of cases throws a IllegalStateException because the app try to re-open the connection or open a closed connection, when I have a method to open database in 6 lines more above. In this cases I think the problem is multiple simultaneous acceses in database, I'm right?

在型动物职位,我可以读,人们谈德的SQLite无法执行的并发连接,它系列化连接,因为文件结构不允许......最后一个问题是,如果我们做的倍数asyncTasks使用SQLite连接做插入,更新和删除,以利用处理器的全部功能与并行编程,我们必须做到这一点的任何工具?或者它是一个非可行的选择,我们需要做一个序列化的连接?

In the differents posts that I can read, the people talk about de SQLite can't execute a simultaneous connections and it serialized connections because file structures not permit... The final question is, If we do multiples asyncTasks with sqlite connections to do inserts, updates and deletes, to harness the full power of the processor with parallel programming, we have any tools for do this? Or it's a non-viable option and we need to do a serialized connections?

如果您对我的任何问题或解决任何想法,帮助我!在此先感谢!

If you have any solutions or any ideas for my problem, help me!! Thanks in advance!!

更多信息:
我BDDclass有打开数据库的方法。当我需要执行查询,rawquery,等等......在一个简单的功能或作废我打电话给我的数据库类,打开数据库,执行查询或多个查询,并在结束时,我们关闭数据库。当我知道我有一个大的进程,倍数功能,在这种情况下,我querys创建BDDclass,并在开始和结束时打开BDD关闭此进程的数据库。

More info: My BDDclass have a method for open database. When I need to execute query, rawquery, etc... in a simple function or void I call my database class, opens database, executes the query or multiple queries and at the end we close the database. When I know that i have a large process with a multiples functions with querys in this case I create BDDclass and opens bdd at start and at the end closes the database of this process.

我这样说是因为我可以看到一些帖子,人们推荐使用SQLiteHelper,因为这有助于管理SQLite中多个同时连接,但其他人的帖子说,有我有同样的问题...那么它必须使用SQLiteHelper ?还是不行?

I say this because I can see some posts that people recommend use the SQLiteHelper because this helps to administrate multiple simultaneous connections in SQLite, but others posts says that have the same problem that I have... Then it's must to use SQLiteHelper? Or not?

如果您需要了解更多信息或某事让我知道。

If you need more information or something let me know.

推荐答案

我终于解决了这个问题!问题是,我试图将控制访问非常到数据库,打开和关闭数据库,当我需要读取或并行编程(背景asyncTasks)数据库写。
必须记住,我不使用SQLiteHelper,我解决了这个问题打电话给我的数据库类活动的每一次,这意味着打开我的数据库一次,并关闭在我的应用程序是暂停和reconect与BDD时,我的应用程序来在其他第一架飞机时间再与我的数据库连接。

Finally I solved the problem!! The problem is that I try to control the acceses to the database, opening and closing the databases when I need read or write in the databases with parallel programming (background asyncTasks). Must remember that I don't use SQLiteHelper and I solved the problem calling my database class one time per activity, this mean open my database one time and close this when my app is pause and reconect with BDD when my app come in first plane other time then connects with my database.

在简历,从来没有关闭您的数据库,并与多个SQLite中访问,你可以使用并行编程。问候!

In resume, never close your database and you can use a parallel programming with multiple accesses in SQLite. Greetings!!

这篇关于多个连接的SQLite同声异步任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆