What about multithreading in Android SQLite?

前端 未结 6 1064
旧巷少年郎
旧巷少年郎 2021-02-05 16:06

In my app I\'ve got to implement some UI and Sync service. It runs in the background and updates data. Sync service is not very simple, it uses multithreading.

So, here

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 16:33

    Use a singleton helper for opening connections.

    1) Open as many readable connections as you want, and close then after your are done with it.

    2) For writable connections, you should open only a single writable connection.

    When attempting to open another writable connection, return the already opened connection. If no writable connection exists, open a new writable connection. Keep a writable_connection counter, and close the writable connection, when all threads are done with it.

    I am about to implement this, and will let you all know if it works when I am done.

提交回复
热议问题