28 lines
1.2 KiB
Java
28 lines
1.2 KiB
Java
package com.nanri.aiimage.config;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.core.task.TaskExecutor;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
@Configuration
|
|
public class TaskFileJobConfig {
|
|
|
|
@Bean("taskFileJobDispatchExecutor")
|
|
public TaskExecutor taskFileJobDispatchExecutor(
|
|
@Value("${aiimage.result-file-job.local-dispatch-pool-size:2}") int poolSize,
|
|
@Value("${aiimage.result-file-job.local-dispatch-queue-capacity:200}") int queueCapacity) {
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
int normalizedPoolSize = Math.max(1, poolSize);
|
|
executor.setCorePoolSize(normalizedPoolSize);
|
|
executor.setMaxPoolSize(normalizedPoolSize);
|
|
executor.setQueueCapacity(Math.max(10, queueCapacity));
|
|
executor.setThreadNamePrefix("task-file-job-dispatch-");
|
|
executor.setWaitForTasksToCompleteOnShutdown(true);
|
|
executor.setAwaitTerminationSeconds(30);
|
|
executor.initialize();
|
|
return executor;
|
|
}
|
|
}
|