I need to do writing into the database from different AsyncTask threads but the problem is that we need to be sure that at one time only one thread should be in the process of writing into the db? My question is if i use the singleton pattern in making the single instance of SQLiteDatabase object all over the application,will that single instance manage the synchronization between different threads or not ? Thanks
Asked
Active
Viewed 2,616 times
2
-
http://stackoverflow.com/questions/5786206/to-to-implement-a-sqlite-manager-for-thread-safe-read-write-access may be helpful – Joachim Isaksson Jul 16 '13 at 10:35
1 Answers
3
My question is if i use the singleton pattern in making the single instance of SQLiteDatabase object all over the application,will that single instance manage the synchronization between different threads or not ?
Yes, it will.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
So if I have `insertItem, updateItem, deleteItem` methods in my `DatabaseLab` class then I don't have to add `Synchronized` keyword before each method? – user25 Dec 31 '18 at 17:16
-
-
@user25: I do not know what is in `DatabaseLab`. Back in 2013, when I wrote this answer, `SQLiteDatabase` had some amount of synchronization inside of it. I do not know how much is there today. Usually, we are using wrappers (e.g., Room) around `SQLiteDatabase`, so I have not researched this point recently. – CommonsWare Dec 31 '18 at 17:22