java - Cannot perform operation because there is no current transaction when inserting into database -


in android application have insert data several sqlite tables different threads (one thread insertion 1 table , there 5 tables). there lot of data use begintransaction() -> settransactionsuccessful() -> endtransaction(); in every thread , threads start simultaneously, in second or third thread got exception:

enter image description here

i use single sqlite connection (singleton) mentioned here nevertheless problem remains.so hope help.thanks in advance!

p.s , if have race conditions other way should use multithreaded insertion?

i think problem race condition. since have multiple threads starting , ending transaction, might following operations:

begintransaction() // may noop because transaction open begintransaction() settransactionsuccessful() settransactionsuccessful() endtransaction() // may throw because previous end closes transaction endtransaction() 

i don't think sqlite supports multiple transactions open on single connection , point out, multiple connections not possible.

if goal of transactions speed data, going have change architecture , not write multiple threads. can use sort of utility class actual database updates synchronized threads call in , decides when open or close transaction. idea have single thread database operations , other threads write blockingqueue shared writing thread.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -