英文:
Project Reactor create multiple scheduler from the same Executor
问题
在我的应用程序中,我有一个单独的Java Executor
,如果我从相同的Executor
实例创建多个Scheduler
,会产生问题吗?类似于以下方式:
public class MyServiceController {
@Autowired
private Executor mainExecutor;
public Object something() {
return Flux.from(somethingElse())
.publishOn(Schedulers.fromExecutor(mainExecutor))
.toFuture()
}
}
(或者多个实现了这种模式的类,它们都使用相同的mainExecutor
实例)
英文:
In my application I have a single java Executor
, can it create issues if I create multiple Scheduler
from the same instance of Executor
, having something like:
public class MyServiceController {
@Autowired
private Executor mainExecutor;
public Object something() {
return Flux.from(somethingElse())
.publishOn(Schedulers.fromExecutor(mainExecutor))
.toFuture()
}
}
(Or having multiple classes implementing this pattern, all of them having the same instance of mainExecutor
)
答案1
得分: 1
在这两种情况下都应该没问题,相同的“Executor”将支持从每个你从中创建的“Scheduler”所生成的所有“Scheduler.Worker”,如果它是一个“ExecutorService”也是如此(尽管包装器的“Scheduler”实现会有所不同)。
为了清晰起见,我仍然会考虑将“Scheduler”作为“Executor”旁边的单例。
英文:
it should be fine in both cases, the same Executor
will back all Scheduler.Worker
spawned by each Scheduler
you create from it, and the same is true if it is an ExecutorService
(albeit with a different Scheduler
implementation for the wrapper).
For clarity, I'd still consider making the Scheduler
a singleton next to the Executor
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论