-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAsyncConfig.java
43 lines (37 loc) · 1.63 KB
/
AsyncConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package life.qbic.datamanager;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionHandler;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
@Configuration
@EnableAsync()
public class AsyncConfig implements AsyncConfigurer {
@Qualifier("asyncTaskExecutor")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Bean("asyncTaskExecutor")
public ThreadPoolTaskExecutor threadPoolTaskExecutor(
RejectedExecutionHandler rejectedExecutionHandler) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(100);
executor.setQueueCapacity(50);
executor.setThreadNamePrefix("async-");
executor.setRejectedExecutionHandler(rejectedExecutionHandler);
this.threadPoolTaskExecutor = executor;
return executor;
}
@Bean
public DelegatingSecurityContextAsyncTaskExecutor taskExecutor() {
return new DelegatingSecurityContextAsyncTaskExecutor(threadPoolTaskExecutor);
}
@Override
public Executor getAsyncExecutor() {
return new DelegatingSecurityContextAsyncTaskExecutor(threadPoolTaskExecutor);
}
}