在HTC Desire的数据库锁定问题 [英] database lock issue in HTC Desire

查看:134
本文介绍了在HTC Desire的数据库锁定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序一个服务越来越从服务器上的数据,并将其插入到表A

如果我去特定的用户界面,我需要从另一个 B表如果背景列表数据       操作是这样做会生成数据库锁定异常。我有两个数据库        操作并行执行每两个不同的表。

这是工作的罚款三​​星gt15801。不过HTC渴望就会生成数据库锁定        错误。

  

HTC渴望 - 插入过程需要91秒

。      

三星gt15801 - 插入过程需要21秒

解决方案

尝试使用一个的 SqliteDatabaseHelper 的并使它的单个实例。的之后的不完成后关闭SqliteDatabase比如你的操作

您可以实现对数据库锁定为看到这个

http://www.sqlite.org/lockingv3.html

当你开始有大量的并发操作,那么你必须使用一个数据库操作

  database.beginTransaction(); / *为开始交易* /
 

和完成对数据库的操作后,你可以使用

  database.setTransactionSuccessful();
database.endTransaction();
 

不过,如果你给错误的事务之间则没有设置 database.setTransactionSuccessful(); ,这样的交易将被回滚

你也可以检查在错误的时间是否当前数据库处于交易或不被 database.inTransaction(); 如果返回true,那么你的交易否则你是不是在交易

你也可以检查当前的数据库是否已锁定或没有通过调用

  database.isDbLockedByCurrentThread();
database.isDbLockedByOtherThreads();
 

这将返回布尔值。

你也可以设置是否要通过

锁定如果将多个线程试图读取并同时写入你的数据库的数据库

  database.setLockingEnabled(布尔);
 

以上删除方法是pcated所以请不要使用去$ P $。

In my application one service is getting data from server and inserting it to table A.

If I go to particular UI, I need to list data from another table B if background operation is doing it will generate database locked exception. I got two database operation done in parallel each on two different table.

It is working fine in samsung gt15801. But htc desire it will generate database locked error.

HTC desire - insertion process takes 91 seconds.

Samsung gt15801 - insertion process takes 21 seconds.

解决方案

Try to use one SqliteDatabaseHelper and make it single instance. After that don't close the SqliteDatabase instance after complete your operations.

You can implement lock on database for that see this

http://www.sqlite.org/lockingv3.html

When you start a database operation which has many concurrent operation then you have to use

database.beginTransaction(); /* for start transaction */

and after completing operation on database you can use

database.setTransactionSuccessful();    
database.endTransaction();

But if you give error in between transaction then don't set database.setTransactionSuccessful(); so that the transaction will be rollback.

Also you can check at the time of error whether currently the database is in transaction or not by database.inTransaction(); if it return true then you are in transaction else you are not in transaction

Also You can check for whether current database has locked or not by calling

database.isDbLockedByCurrentThread();
database.isDbLockedByOtherThreads();

this will return Boolean.

Also you can set whether you want to lock your database if multiple threads are trying to read and write your database at the same time by

database.setLockingEnabled(boolean);

Above deleted methods are deprecated so please do not use.

这篇关于在HTC Desire的数据库锁定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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