-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from Lixuhuilll/cancel-emailservice-circular-…
…dependency 去除 EmailService 中的循环依赖,避免与 AOT 的兼容性问题
- Loading branch information
Showing
2 changed files
with
57 additions
and
23 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/plus/maa/backend/config/ThreadPoolConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package plus.maa.backend.config; | ||
|
||
import org.springframework.boot.task.TaskExecutorBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
import static org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
public class ThreadPoolConfig { | ||
|
||
@Lazy | ||
@Primary | ||
@Bean(name = {APPLICATION_TASK_EXECUTOR_BEAN_NAME, | ||
AsyncAnnotationBeanPostProcessor.DEFAULT_TASK_EXECUTOR_BEAN_NAME}) | ||
public ThreadPoolTaskExecutor defaultTaskExecutor(TaskExecutorBuilder builder) { | ||
return builder.build(); | ||
} | ||
|
||
@Bean | ||
public ThreadPoolTaskExecutor emailTaskExecutor() { | ||
// 在默认线程池配置的基础上修改了核心线程数和线程名称 | ||
var taskExecutor = new ThreadPoolTaskExecutor(); | ||
// I/O 密集型配置 | ||
taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); | ||
taskExecutor.setThreadNamePrefix("email-task-"); | ||
// 动态的核心线程数量 | ||
taskExecutor.setAllowCoreThreadTimeOut(true); | ||
return taskExecutor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters