40 lines
1.4 KiB
Java
40 lines
1.4 KiB
Java
package SuMoC.backend.config;
|
|
|
|
import SuMoC.backend.suggestion.config.RegularTripSuggestionProperties;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
@Configuration
|
|
@EnableAsync
|
|
@RequiredArgsConstructor
|
|
public class AsyncConfiguration {
|
|
|
|
private final RegularTripSuggestionProperties regularTripSuggestionProperties;
|
|
|
|
/**
|
|
* Custom thread pool executor for parallel processing of regular trip suggestions.
|
|
* Configured with parallelism setting from application properties.
|
|
*/
|
|
@Bean(name = "regularTripSuggestionExecutor")
|
|
public Executor regularTripSuggestionExecutor() {
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
int parallelism = regularTripSuggestionProperties.getParallelism();
|
|
|
|
executor.setCorePoolSize(parallelism);
|
|
executor.setMaxPoolSize(parallelism);
|
|
executor.setQueueCapacity(500); // Queue capacity for pending tasks
|
|
executor.setThreadNamePrefix("regular-trip-");
|
|
executor.setWaitForTasksToCompleteOnShutdown(true);
|
|
executor.setAwaitTerminationSeconds(60);
|
|
executor.initialize();
|
|
|
|
return executor;
|
|
}
|
|
}
|
|
|