I was wondering what consequences were of calling subscribeOn() on a Subject were.
I understand that (by default) this won't change what thread items are emitted on, I'm just curious if it could cause some other negative side effects.
In general, is calling subscribe() to the same Observable from different threads unsafe? If it is, does subscribeOn() somehow make this safe?
Calling subscribe()
on the same Subject
from different threads is safe (note that calling subject.doOnXXX
from different threads needs synchronization, ask for clarification if you need it). Generalizing that to all Observables is not possible because it is easy enough to construct one that is not thread-safe (say with visibility issues). Your are right in that you might make a non-thread-safe Observable thread-safe by using
.subscribeOn(Schedulers.from(Executors.newSingleThreadExecutor()))
Using a scheduler with more than one thread will not protect you in terms of thread safety.