I was wondering if I can use the RxJava library to add some concurrency to the following use case:
- Select
String
columns sequentially from an existing ResultSet
with a custom Observable
(something like ResultSetObservable.create(resultSet)
) - Call a web service for each of these values (for example, with an instance of
InvokeWebServiceFunc1<String, Pair<String, Integer>>()
) to get some statistics related to String
(note that String
in Pair
like the one was entered into the entrance) - Print everything in CSV format (using
ExportAsCSVAction1<Pair<String, Integer>>(PrintStream printStream)
).
So here is what I have:
ResultSetObservable.create(resultSet) .map(new InvokeWebServiceFunc1<String, Pair<String, Integer>>()) .subscribe(new ExportAsCSVAction1<Pair<String, Integer>>(System.out));
It works well, but since the web service may take some time for some String
input, I want to add using a pool of threads, such as display behavior (of 10 threads, for example), but I need ExportAsCSVAction0
to be called in the same stream (and actually the current stream would be ideal).
Could you help me? I cannot understand if the toBlocking().forEach()
template is used correctly, and I do not understand where to use Schedulers.from(fixedThreadPool)
(in observeOn()
or in subscribeOn()
).
Thanks for the help!
source share