android - When should I do certain SQLite operations on another thread(not the main thread)? -
my android application includes sqlite database sqliteopenhelper
class manage it. during application use, user may perform operations such adding/deleting/updating etc on database.
at points size of operation known, this:
- user clicks button save item
- the
sqlitedatabase
performs singleinsert
query - user continues using app
at other areas of app, operation may large, inserting 10+ items database @ once.
questions:
- should thread simple operations inserting/updating/deleting/viewing 1 item?
- will take longer insert 1 item table contains many items(like 30+) take insert table no items?
- if don't need thread such simple operations, @ point suggest start threading them?
when thread mean using thread not main ui thread.
edit: realize small operations not take time , away doing them on main thread. concerned bad practice executing them on main thread , clarification!
general rule everything: if it's fast enough, on main thread. if not, use worker thread.
unless have ridiculously huge database, single operation never warrants separate thread. databases in general designed scale well, of course big database (10,000+ rows?) bit slower small one. 30 rows, however, nothing.
i start threading stuff if have lot of operations going on, bunch of queries, or complicated queries span several tables.
as - profile app, , if it's slow, optimize. don't write awesome synchronized super-duper multi-core-ready database handler if none of queries takes longer 2ms.
Comments
Post a Comment