Spring:Flux 无法运行多个请求
温馨提示:
本文最后更新于 2024年04月12日,已超过 47 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
It worked well after many tests. But at some point I logged back in with an account and it stopped working. And log this error: " org.springframework.dao.DataAccessResourceFailureException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection Caused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30001ms." at runtime and when the client uses eventSource.close()
In JS, i use eventSource to call this api. This is my code:
@Override
public Flux<ServerSentEvent<List<NhacNhoResponseDto>>> getBy(@NonNull String orgId) {
return Flux
.interval(Duration.ofSeconds(3))
.doOnCancel(() -> System.out.println("Cancel"))
.onErrorResume(e -> {
System.out.println("Error occurred: " + e.getMessage());
return Flux.empty();
})
.publishOn(Schedulers.parallel())
.map(sequence -> ServerSentEvent.<List<NhacNhoResponseDto>>builder()
.id(String.valueOf(sequence)).event("quantity-reminder-event")
.data(getData(orgId) )
.build());
}
@GetMapping("/nhac-nho")
@Async("taskExecutor")
public CompletableFuture<Flux<ServerSentEvent<List<NhacNhoResponseDto>>>> getBy(@RequestParam("orgId") String orgId) {
return CompletableFuture.completedFuture(nhacNhoService.getBy(orgId));
}`
`@Configuration
public class AsyncConfig implements AsyncConfigurer {
@Bean
protected WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setTaskExecutor(new ConcurrentTaskExecutor(Executors.newFixedThreadPool(10)));
}
};
}
@Bean
protected ConcurrentTaskExecutor getTaskExecutor() {
return new ConcurrentTaskExecutor(Executors.newFixedThreadPool(10));
}
}
Can you give me some suggested keywords or solutions to solve this problem?
正文到此结束
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2211
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
热门推荐
-
浏览(192) 评论(0)