原创

Spring: Flux cant run with multiple request

温馨提示:
本文最后更新于 2024年04月12日,已超过 48 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

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?

正文到此结束
热门推荐
本文目录