I'm trying to understand how observable works and I'd like to show the current thread to get a better understanding. The whole app is built with java 8 and make use of lambda expressions. No having much experience with it I'm finding some troubles to show my current thread in an expression like this:
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.flatMap(..... -> {
I like to put something like this:
log.info("Current Thread:", Thread.currentThread().name)
But I couldn't find a way to do it as subscribeOn(Schedulers.io()) and observeOn(Schedulers.computation()) return and Single and there is no way to put something like this:
.subscribeOn(Schedulers.io())
.log.info("Current Thread:", Thread.currentThread().name)
.observeOn(Schedulers.computation())
.log.info("Current Thread:", Thread.currentThread().name)
.flatMap(..... -> {
Thanks
You are trying just to log the current Thread, correct?
Just use map
for log and return the same value:
.subscribeOn(Schedulers.io())
.map(it -> {
log.info("Current Thread:", Thread.currentThread().name)
return it;
})
.observeOn(Schedulers.computation())
.map(it -> {
log.info("Current Thread:", Thread.currentThread().name)
return it;
})
.flatMap(..... -> {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.