Skip to content

Commit

Permalink
threadpoolconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sizegang1 committed Mar 9, 2022
1 parent afee181 commit 26c26a4
Showing 1 changed file with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import javax.annotation.PostConstruct;
import java.util.concurrent.*;

/**
* @program: gobrs-async
Expand All @@ -23,23 +23,12 @@ public class ThreadPoolConfig {
@Autowired
private GobrsAsyncThreadPoolFactory factory;

private ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) Executors.newCachedThreadPool();

@Bean
public ThreadPoolTaskExecutor gobrsThreadPoolExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setBeanName("jd-thead-pool");
executor.setCorePoolSize(1000);//配置核心线程数
executor.setMaxPoolSize(2000);//配置最大线程数
executor.setKeepAliveSeconds(30);
executor.setQueueCapacity(10000);//配置队列大小
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());//拒绝策略
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.initialize();//执行初始化

@PostConstruct
public void gobrsThreadPoolExecutor(){
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(300, 500, 30, TimeUnit.SECONDS,
new LinkedBlockingQueue());
factory.setThreadPoolExecutor(threadPoolExecutor);
return executor;
}


}

0 comments on commit 26c26a4

Please sign in to comment.