后端架构更新
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user