Creating Thread Dynamically with Spring-boot

Asked

Viewed 721 times

-1

Good morning earthlings,

There is the possibility to make spring-boot create thread when needed and also kill the same ?

1 answer

0

Enter the annotation @EnableAsync in his Application.java and give a extends in class AsyncConfigurerSupport. With this it will be possible to create a ThreadPoolTaskExecutor, following example below.

 @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(2);
        executor.setQueueCapacity(500);
        executor.setThreadNamePrefix("GithubLookup-");
        executor.initialize();
        return executor;
    }

Follow the link from the Spring Boot guide itself: https://spring.io/guides/gs/async-method/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.