sách gpt4 ai đã đi

java - Spring WebFlux WebClient timeout() 和 exchange()

In lại 作者:搜寻专家 更新时间:2023-11-01 03:31:31 26 4
mua khóa gpt4 Nike

我有类似于以下示例的代码:

Mono<>> result = webClient
.post()
.body(Mono.just(command), MyCommand.class)
.exchange()
.timeout(calculateTimeout(command))
.flatMap(clientResponse -> clientResponse.toEntity(String.class));

spring documentationgiải thích:

When using exchange() you must always use any of the body or toEntity methods of ClientResponse to ensure resources are released and to avoid potential issues with HTTP connection pooling. You can use bodyToMono(Void.class) if no response content is expected. However keep in mind that if the response does have content, the connection will be closed and will not be placed back in the pool.

问题:如果上面代码中的 timeout(...) 触发了 TimeoutException,我是否必须明确地做一些事情来确保所有资源都被正确释放或者上面的代码是否足够?我想避免在这里发生内存泄漏。

1 Câu trả lời

在这种情况下,我认为这不是问题。

触发时,thời gian chờ SẽHủy bỏ() 上游,有效地关闭连接并且不将其返回到连接池。您不需要在这里做任何特别的事情,也不会有内存泄漏(除了已经位于 react 器内部队列中的缓冲区,这是 Spring Framework 将在 SPR-17025 中解决的问题)。

关于java - Spring WebFlux WebClient timeout() 和 exchange(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51937483/

26 4 0
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com