Android Database Locking Behaviour -
i still haven't wrapped head around synchronization. know it's there, know why it's used , idea behind it, im lacking practical skill , real world examples understand how works , how it's implemented when several activies trying read/write database @ same time. share objects through application, or system intelligent enough synchronize various objects of same type?
perhaps content provider better way go understand has built in sync.
i digress though.
im still confused on database activity. remember have service running every 60 seconds in background reading same table update function writing to. yes im looking change this, right want understand database handling in android more , work out what's happening.
if have loop such as:
db = provider.getreadabledatabase(); while(theres_still_work_today) { do_some_calculations; update_database; } provider.close();
this works fine standalone. if try , place in thread, errors galore locking. when run this:
while(theres_still_work_today) { do_some_calculations; db = provider.getreadabledatabase(); provider.close(); update_database; }
i find bizarrely, seems faster, , gives no locking issues.
am being incredibly lucky don't 2 events triggering @ same time causing lock? there kind of timeout built database handling in android/sqlite?
i don't understand why last bit of code should work ok, , why should work faster?
im not entirely confident android emulator though. if use first option single open/close outside loop, can through long long loop fine though service triggers in background.
other times crashes on whim.
i don't know why "isdatabaselockedbyotherthreads()" not report locked other threads.
any advice?
thanks simon
Comments
Post a Comment