【发布时间】:2019-12-17 11:05:45
【问题描述】:
我有一个 Spring Webflux Annotated 控制器,如下所示,
@RestController
public class TestBlockingController {
Logger log = LoggerFactory.getLogger(this.getClass().getName());
@GetMapping()
public Mono<String> blockForXSeconds(@RequestParam("block-seconds") Integer blockSeconds) {
return getStringMono();
}
private Mono<String> getStringMono() {
Integer blockSeconds = 5;
String type = new String();
try {
if (blockSeconds % 2 == 0) {
Thread.sleep(blockSeconds * 1000);
type = "EVEN";
} else {
Thread.sleep(blockSeconds * 1000);
type = "ODD";
}
} catch (Exception e) {
log.info("Got Exception");
}
log.info("Type of block-seconds: " + blockSeconds);
return Mono.just(type);
}
}
如何让 getStringMono 在与 Netty 服务器线程不同的线程中运行。我面临的问题是,当我在服务器线程中运行时,吞吐量基本上会减少(每秒 2 个请求)。如何在单独的线程中运行 getStringMono。
【问题讨论】:
标签: spring-boot spring-webflux project-reactor