项目 Reactor 从同一 Executor 创建多个调度程序

huangapple go评论77阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年10月21日 21:37:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/64464774.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定