2

I am using SQLite DB and I have multiple threads using a single connection. As per https://www.sqlite.org/threadsafe.html I think I need to use serialized mode.

How can I set threading mode in Java? I mean method?

SQLiteConfig config = new SQLiteConfig();
config.setOpenMode(SQLiteOpenMode.FULLMUTEX);
dbc = DriverManager.getConnection(jdbcPath,config.toProperties());

Is there any relation between SQLiteOpen mode and Threading Mode ?

SQLite supports three different threading modes:

Single-thread. In this mode, all mutexes are disabled and SQLite is unsafe to use in more than a single thread at once.

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.

Serialized. In serialized mode, SQLite can be safely used by multiple threads with no restriction.

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
Ashok
  • 601
  • 1
  • 17
  • 32
  • https://stackoverflow.com/questions/10707434/sqlite-in-a-multithreaded-java-application – tuxdna Jan 31 '17 at 07:16
  • @tuxdna that link suggesting me to have Share the same JDBC connection among all threads, thats what I am doing it now, But I want to make sure "Threading Mode is Set to Serialized", how can I do that? Sorry If I misinterpret the answer link, but I am not sure how to set threading mode? in Java – Ashok Jan 31 '17 at 07:24

1 Answers1

2

From the link you posted:

The default mode is serialized.

If you want to explicitly select the serialized mode (or switch back to it), then use SQLiteOpenMode.FULLMUTEX as is also described in the docs.

user229044
  • 232,980
  • 40
  • 330
  • 338
Kayaman
  • 72,141
  • 5
  • 83
  • 121