Ormlite multiple-thread guide/resources?

350 views
Skip to first unread message

Ormlite user

unread,
Dec 10, 2016, 2:39:54 PM12/10/16
to ORMLite Users
Can anyone guide to some resources about multiple thread synchronizing in OrmLite, I was not able to find one.

I am using JdbcPooledConnectionSource for connection which should be fine for multiple threads , but I do not know how ormlite behaves when using multiple threads to perform CRUD operation over database.

I need this because I am getting error ,when using mulitple threads.

Exception in thread "pool-1-thread-38" java.lang.IllegalStateException: Could not create data element in dao
...
Caused by: java.sql.SQLException: Unable to run insert stmt on object ...
...
Caused by: java.sql.SQLException: [SQLITE_BUSY]  The database file is locked (database is locked)


Gray Watson

unread,
Dec 11, 2016, 9:51:55 AM12/11/16
to ORMLite Users
This is not about ORMLite, this sounds like it is about the underlying database -- in this case, SQLite. SQLite has database locks which you seem to be hitting. As far as I know, you are not allowed to be using a pooled connection source because only one connection is allowed to a SQLite database at at time. See:

https://www.sqlite.org/threadsafe.html

Specifically: Multi-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.

I believe SQLite is compiled in Android as "multi-thread". You can also look at:

https://nfrolov.wordpress.com/2014/08/16/android-sqlitedatabase-locking-and-multi-threading/

Hope this helps,
gray
> --
> You received this message because you are subscribed to the Google Groups "ORMLite Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ormlite-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages