Java 8 同一流中fromCallable()和subscribeOn()时的线程行为
我在JavaSpringReactor中使用Java 8 同一流中fromCallable()和subscribeOn()时的线程行为,java-8,reactive-programming,publish-subscribe,project-reactor,Java 8,Reactive Programming,Publish Subscribe,Project Reactor,我在JavaSpringReactor中使用.fromCallable()创建了一个Mono。我认为它将异步运行我提供的lambda,并使用Mono.empty()作为返回值。因此,整个流的执行将从不同的线程开始 我有两个问题: 如果我在操作链中调用.subscribeOn(),执行顺序和线程数是多少 我遵循这种方法来检查我下面的代码中的响应状态是否正确吗 private final Scheduler myScheduler = Schedulers
.fromCallable()
创建了一个Mono
。我认为它将异步运行我提供的lambda,并使用Mono.empty()
作为返回值。因此,整个流的执行将从不同的线程开始
我有两个问题:
.subscribeOn()
,执行顺序和线程数是多少private final Scheduler myScheduler = Schedulers
.newParallel("reactive-pricefetcher", 10, true);
...
...
...
final Mono<Mono<Object>> callableMono = Mono
.fromCallable(() -> {
myHandler.updateCacheResponse(mutableObjList,
dealsRequest.getDealParameters()
);
return Mono.empty();
})
.subscribeOn(myScheduler);
callableMono.subscribe();
boolean stillInProgress = mutableObjList.stream()
.anyMatch(obj -> obj.getStatus() != DONE);
return DealsResponse.builder()
.complete(!stillInProgress)
.itemDeals(mutableObjList)
.build();
private final Scheduler myScheduler=调度程序
.newParallel(“反应性价格获取器”,10,真);
...
...
...
final Mono callableMono=Mono
.fromCallable(()->{
myHandler.UpdateCacherResponse(mutableObjList,
dealsRequest.getDealParameters()
);
返回Mono.empty();
})
.subscribeOn(myScheduler);
callableMono.subscribe();
布尔stillInProgress=mutableObjList.stream()
.anyMatch(obj->obj.getStatus()!=DONE);
return DealsResponse.builder()
.完成(!仍在进行)
.itemDeals(可变对象列表)
.build();
PS:我已经知道,当调用
subscribe()
时,使用.subscribeOn()
会将整个流链移动到不同的线程中。尽量简化您的问题。这里有很多东西不清楚它来自哪里,它的作用是什么,比如cacheResponse
或DealsResponse
@MartinTarjányi编辑了这个问题,试图简化你的问题。这里有很多东西不清楚它是从哪里来的,它的作用是什么,比如cacheResponse
或DealsResponse
@MartinTarjányi编辑了这个问题