Tuesday, October 11, 2011

Re: [android-developers] SQLite locking

On Wed, Oct 12, 2011 at 10:11 AM, Zsolt Vasvari <zvasvari@gmail.com> wrote:
> How do the
> android.database.sqlite.SQLiteDatabase.isDbLockedByCurrentThread() and
> isDbLockedByOtherThreads() methods work?

They use a java.util.concurrent.locks.ReentrantLock. execSQL(), etc. call
lock()/unlock() in a try/finally block. The effect is similar to using
synchronized on these methods.

>
> To be able to use them, you must open the database first with either
> OPEN_READONLY or OPEN_READWRTE modes, which seems like putting the
> cart before the horse.
>

The lock is for synchronization of the SQLiteDatabase instance methods,
so you need to create an instance.

> Can I assume that even if a DB is locked for read/wite, I can still
> open it in read only mode?

IIRC, sqlite uses a file lock for the DB file, and allows concurrent
selects from multiple processes. So unless Android changes
the default behaviour in some way, yes.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment