0

I see some answers about this but they do not point in my direction.

When writing to SQLite all concurrent reads/writes will throw an exception.
This is going to be a problem for my setup since i have:

java background service
java Desktop gui application

Both accessing the same SQLite on the same computer.
Is there some global Singelton setup to deal with this.

Any ides would be grate

3
  • 2
    What driver are you using to access SQLite? It sounds like you just need to turn on the concurrency features Commented Nov 18, 2011 at 23:13
  • I want to use sqlite4java. Was it that easy, good Commented Nov 18, 2011 at 23:14
  • @Brendan Long thanks i will read up on this Commented Nov 18, 2011 at 23:20

1 Answer 1

1

From the sqlite4java page:

Single-threaded model - each SQLite connection is confined to a single thread, all calls must come from that thread. Application may open several connections to the same database from different threads. Along with the Serializable isolation level from SQLite, this feature facilitates writing very clean and predictable code.

So you need to either:

  • Have a dedicated thread that talks to SQLite
  • Open a new connection for each thread
Sign up to request clarification or add additional context in comments.

4 Comments

It sound like i should use a singelton class for the db connection. What do you think?. Just found this example: danfolkes.com/2011/05/20/…
@Erik - A singleton won't work if you're accessing it from multiple threads.
I will actually not have multiple threads. Another thing is this with that i have two java applications. you say turn on the concurrency features. Does that mean that my "reads/write" will be synchronized and go into wait mode if the other java app have the write lock.
@Erik - It sounds like the library you're using is fine with two programs using the same database by default, and yes it will use some kind of locking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.