gpt4 book ai didi

spring-webflux - @Scheduled 和 Spring webflux

转载 作者:行者123 更新时间:2023-12-03 14:49:07 26 4
gpt4 key购买 nike

我正在寻找一种在响应式(Reactive) API 中使用计划任务的方法。
我知道它使用线程池,所以它与 webflux 组件不太兼容。
你有同等的人来做这项工作吗?

非常感谢

萨维留

最佳答案

有几种方法可以做到。考虑到您想如何安排它,您也可以使用以下方法。

@Configuration
class ApplicationConfiguration() {

@PostConstruct
fun init() {

Flux.interval(Duration.ofMinutes(12))
.onBackpressureDrop()
.flatMap { /* some task that return Mono<T> */ }
.subscribeOn(Schedulers.boundedElastic())
.subscribe()
}
}
请注意 subscribeOn(Schedulers.boundedElastic())除非调用阻塞,否则不需要。我也在使用 onBackpressureDrop但您的要求可能与此不同。

关于spring-webflux - @Scheduled 和 Spring webflux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54093132/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com