Mark M. | has entered the room |
Mark M. | turned on guest access |
Feb 16 | 7:30 PM |
Mike | has entered the room |
Feb 16 | 7:35 PM |
Mike |
Hi Mark, how are you?
|
Feb 16 | 7:35 PM |
Mark M. |
fine, and you?
|
Mike |
View paste
|
Mark M. |
that's a good question
|
Mark M. |
my gut instinct is: try your best to avoid needing to synchronize an operation across processes :-)
|
Mike |
:)
|
Mark M. |
I don't recall the Android SDK having a cross-process synchronization mechanism
|
Mark M. |
if you're willing to go into the NDK, you should have some options
|
Mike |
I found this but I don't know how good it is http://stackoverflow.com/questions/23893431/how...
|
Mark M. |
that's one of those "it might work, but it seems scary" solutions
|
Mike |
yep
|
Mark M. | |
Feb 16 | 7:40 PM |
Mike |
Thank you. Never heard of it, I will have to search for some examples.
|
Mark M. |
neither have I; just perusing android.os looking for options
|
Mark M. |
not sure how you use it, considering that it's abstract
|
Mark M. |
but the nice thing about binders is that they are indeed cross-process tokens
|
Mark M. |
but, other than that and doing something in the NDK, I don't have any great ideas
|
Mark M. |
(plus the one that you posted)
|
Mike |
how about using file locking
|
Mark M. |
I don't know that Java has strong enough direct support for that, though
|
Mike |
not sure if it's even possible. I was thinking one process could open exclusively a file
|
Mark M. |
Android, in terms of being based on Linux, definitely supports file locking
|
Mark M. |
but through the Android SDK, by way of Java, a lot of that gets lost
|
Mike |
thing is I want to synchronize SQLite Db access
|
Mike |
one of my services could run in a separate process
|
Feb 16 | 7:45 PM |
Mike |
because of the Android 6 issue with foreground service (if it's in same process with activity it gets killed)
|
Mike |
not sure if you remember we talked the other day
|
Mark M. |
I remember you being in the chat; I don't remember the details of the chat itself
|
Mike |
or
|
Mark M. |
in theory, SQLite does its own process-level locking
|
Mark M. |
that's a SQLite thing, not an Android thing
|
Mike |
I see
|
Mark M. |
so, in principle, with proper transactions, you may be OK
|
Mark M. |
but it's the sort of thing I'd want to beat up fairly seriously in a test suite
|
Mark M. | |
Mark M. |
and https://www.sqlite.org/wal.html for write-ahead locking
|
Mike |
thanks
|
Mark M. |
going back to your file-locking idea: https://developer.android.com/reference/java/ni...
|
Feb 16 | 7:50 PM |
Mark M. |
that turned up when hunting around for who all has tried doing multi-process SQLite on Android, and running across: https://github.com/pardom/ActiveAndroid/issues/311
|
Mike |
:)
|
Mike |
Someone wrote "In Android, FileLock works between processes, but does not work between threads in a process."
|
Mark M. |
that makes sense
|
Mike |
how come?
|
Mike |
a process has a thread
|
Mark M. |
a process can have N threads
|
Mike |
sure.
|
Mark M. |
that comment is saying that FileLock does not do inter-thread locking within a single process
|
Mike |
why wouldn't it work across threads in same process?
|
Mark M. |
it's probably backed by POSIX stuff that works at the process level
|
Mike |
:(
|
Mike |
doesn't make sense to me. it's a file ...
|
Mark M. |
quoting the JavaDocs: " File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine. "
|
Mark M. |
apparently, that scope was a decision made by Sun, back when they added FileLock to Java
|
Mike |
I see
|
Mark M. |
back to the SQLite locking, see also section #2 in http://sqlite.org/howtocorrupt.html
|
Feb 16 | 7:55 PM |
Mark M. |
another possibility would be for you to use a ContentProvider to expose access to the database (from your main process) to the service (running in the separate process)
|
Mike |
makes my head spin. I think that's why I got the idea from somewhere it's better to do your own locking
|
Mark M. |
that way, all database I/O runs through one process
|
Mike |
I need to refresh my memory but AFAIK ContentProvider requires an Activity
|
Mark M. |
nope
|
Mike |
ok I will do some research
|
Mark M. |
your app needs an activity, in order for any of your code to run
|
Mark M. |
but a ContentProvider itself is not tied to an activity
|
Mark M. |
my guess is that this will be an area that gets more attention in the coming years, due to the sorts of problems that you're running into
|
Mark M. |
that, of course, does not exactly help you now
|
Mike |
thank you Mark
|
Mark M. |
sorry that I didn't have a sure-fire silver bullet for you
|
Mike |
not a problem
|
Feb 16 | 8:00 PM |
Mike |
discussion has been very helpful to me
|
Mike |
I will stick around
|
Feb 16 | 8:30 PM |
Mark M. |
that's the end of today's chat
|
Mark M. |
the transcript will appear on https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Tuesday, also at 7:30pm US Eastern
|
Mark M. |
have a pleasant day!
|
Mike | has left the room |
Mark M. | turned off guest access |