What is the Default Threading mode of SQLite in Android?
Asked Answered
C

2

11

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

From above link I came to know, SQLite support three different threading modes : Single-thread,Multi-thread and Serialized. I am just curious to know "What is the Default Threading mode of SQLite in Android"? is there any way to change Threading mode pragmatically? If so, how and what are the advantages I get? When to choose which one with some sample cases?

Thanks In Advance.

Cabal answered 23/6, 2012 at 7:52 Comment(0)
M
6

Default Mode - Serialized

By default SqliteDatabase is Thread safe, you can check it on the Android Docs,

setLockingEnabled(boolean lockingEnabled)

From the Docs -

Control whether or not the SQLiteDatabase is made thread-safe by using locks around critical sections. This is pretty expensive, so if you know that your DB will only be used by a single thread then you should set this to false. The default is true.

Mediatize answered 23/6, 2012 at 8:4 Comment(5)
Yes, as Sqlite Docs declare that it is - The default mode is serialized.Mediatize
Tx. Is there any way to switch between single and multi thread modes or any way to override them at start time as mentioned in the link. Once again Tx for quick response.Cabal
No, currently I have no idea about changing mode.Mediatize
@vrs The SQLite docs mention that the threading parameter must be set at init time, so I don't think it's possible to change once the database is running. sqlite.org/threadsafe.html I don't imagine this has changed on Android.Floridafloridia
Just a heads-up, setLockingEnabled has been deprecated as of API 16Displume
S
0

Threading mode of sqlite can be configured in compile-time, start-time and runtime.

Run-time overrides start-time and start-time overrides compile-time. Except, single-thread mode cannot be overridden once selected. See sqlite threadsafe

Android use Serialized in compile time. See sqlite Android.bp.

However, starts from 4.2.2, android select Multi-thread in start-time. See android_database_SQLiteGlobal.cpp

Scenography answered 26/8, 2021 at 4:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.