Closed drayan85 closed 6 years ago
you code is running on main Thread if
Thread.currentThread().getName().equals("main");
@mjohenneken yeah, I can see that method is executed in the main thread. I didn't change any code from this repository after clone. I am just wondering it suppose to run on worker thread which is created in JobExecutor Thread pool.
@drayan85 It's fine for that userEntityDetails() is running on the main thread. That's expected behavior. what you should be checking is if this.userCache.get(userId)
is being called on the main thread, since that's actually the observable. Anything outside the observable chain will not run on your executor thread. so... if you did this:
@Override
public Observable<UserEntity> userEntityDetails(final int userId) {
return this.userCache.get(userId).map(val->{
System.out.println("DiskUserDataStore Thread ID : " + Thread.currentThread().getId());
return val;
});
}
That should be on the executor thread, because it's part of the observable chain. I hope that makes sense. And do note some operations do not run on the executor thread by default, like doOnNext() and others definitely check out the docs or test before making an assumption of what thread an operation executes on. That has bitten me several times.
@alexwhb Thanks. I got the point.
I Have added the below Line in
DiskUserDataStore
classIt is Printing below Line:
01-25 13:45:39.470 3117-3117/com.fernanependocejas.android10.sample.presentation I/System.out: DiskUserDataStore Thread ID : 1
Is that mean that method has been executed in main thread instead of running in one of the thread which should have been created in JobExecutor Thread pool?