Skip to content Skip to sidebar Skip to footer

Database Queue For Android Sqlite

I have an Android Application that holds a fairly large Database which is accessed from multiple threads. I am starting to get Database locked Exceptions. My question, is there a w

Solution 1:

My question, is there a way of creating a database Queue

Move all your database writes to an IntentService, a regular service hosting a LinkedBlockingQueue, a LinkedBlockingQueue held by your singleton SQLiteOpenHelper, etc.

a lot of my database queries and inserts are different so creating a method for each query is not feasible.

The overhead to wrap a database I/O in a method not especially much, less than what you were proposing doing in your question.

if the db is locked for 10ms I will be waiting for 990ms for the query to run, which is not great for user experience

Tune your database access (e.g., EXPLAIN keyword, then set up appropriate indices). Use Traceview to determine exactly where your problems lie. If your problems are in a database transaction (e.g., you open your own transaction and do a ton of work inside of it), consider using yieldIfContendedSafely().

Post a Comment for "Database Queue For Android Sqlite"