@Bean("threadPoolExecutor") public ThreadPoolTaskExecutor taskExecutor() {…
- User
@Bean("threadPoolExecutor") public ThreadPoolTaskExecutor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(corePoolSize); executor.setMaxPoolSize(maxPoolSize); executor.setQueueCapacity(queueCapacity); executor.setKeepAliveSeconds(keepAliveSeconds); executor.setThreadNamePrefix("threadPoolExecutor>>>"); executor.setWaitForTasksToCompleteOnShutdown(true); executor.setAwaitTerminationSeconds(awaitTerminationSeconds); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize(); log.info("ThreadPool init ! "); return executor; }
- Assistant
This Java method is defining and configuring a
ThreadPoolTaskExecutorbean in a Spring application. The method is annotated with , which indicates that it returns an object that should be registered as a bean in the Spring application context. It is named to distinguish it within the context. Let's break down the configuration: