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:
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
Post a Comment