Skip to content

Instantly share code, notes, and snippets.

@arleighdickerson
Created July 20, 2025 19:20
Show Gist options
  • Save arleighdickerson/186c7eabeab608b4de0651e6d15cb703 to your computer and use it in GitHub Desktop.
Save arleighdickerson/186c7eabeab608b4de0651e6d15cb703 to your computer and use it in GitHub Desktop.
import io.arleigh.gantry.ServicesApplication;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.boot.autoconfigure.task.TaskExecutionProperties;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@Slf4j
@Configuration
@EnableScheduling
@EnableAsync(mode = AdviceMode.ASPECTJ, proxyTargetClass = ServicesApplication.PROXY_TARGET_CLASS)
@RequiredArgsConstructor
class AsyncConfig extends AsyncConfigurerSupport {
private final TaskExecutionProperties taskExecutionProperties;
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(taskExecutionProperties.getPool().getCoreSize());
executor.setMaxPoolSize(taskExecutionProperties.getPool().getMaxSize());
executor.setQueueCapacity(taskExecutionProperties.getPool().getQueueCapacity());
executor.setThreadNamePrefix(taskExecutionProperties.getThreadNamePrefix());
return executor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment