Android SQLite, big Data processing, simultaneous reading and writing

Source: Internet
Author: User

1. Batch write, use the way of things, first cache the data, then bulk write data, greatly improve the speed

288, direct inset into time 7 seconds

8,640, batch write time 5-7 seconds

[Java]View Plaincopy
  1. try {
  2. this.myDataBase.beginTransaction (); //Manually set the start transaction
  3. For (int i = 0; i < objarr.length; i++) {
  4. This.myDataBase.execSQL (Sql[i]);
  5. }
  6. this.myDataBase.setTransactionSuccessful (); //SET transaction successfully, do not set automatically rollback does not commit
  7. Iresult = true;
  8. return iresult;
  9. } catch (SQLException e) {
  10. E.printstacktrace ();
  11. LOG.E ("Log", E.getmessage ());
  12. return iresult;
  13. } finally {
  14. this.myDataBase.endTransaction (); //processing complete
  15. This.myDataBase.close ();
  16. }



2. Simultaneous reading and writing

SQLite allows 1 reads, writes more,

Getreadabledatabase to read (the underlying is to open the write format, and then to read-only mode, if the system is low on memory, then open for read-only mode)

Curse cur, cur before doing the operation (such as Movetofirst () ... ) is just a pointer and does not operate on the database.

Getwritabledatabase for writing

There is an exclusive relationship between the open modes of the two operations databases, and the underlying synchronization lock

Android SQLite, big Data processing, simultaneous reading and writing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.