Serhad Burakan Serhad Burakan - 4 months ago 13
reST (reStructuredText) Question

Rest Service with Java Observable from Executer Service

I have a rest web service which returns DeferredResults. I implemented JavaRx Observable from executer service that returns Future. I wanted this web service to be non blocking but it seems it is blocking the operation.

Do you think the way I used executer service is healthy?

DeferredResult result = new DeferredResult();
Observable<ResultEntity> observable = Observable
.from(executerService.submit(callable));
observable.subscribe(new Subscriber<ResultEntity>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable throwable) {
result.setErrorResult(throwable.getMessage());
}

@Override
public void onNext(ResultEntity r) {
result.setResult(t);

}

});

Answer

Observable.from(Future) is blocking operation, as mentioned in documentation. You should use Observable.from(Future,Scheduler) instead.