Advertisement
Guest User

Configurator

a guest
Mar 31st, 2017
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.31 KB | None | 0 0
  1. package it.dstech.cloud.configuration;
  2.  
  3. import java.util.concurrent.Executor;
  4.  
  5. import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
  6. import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.scheduling.annotation.AsyncConfigurer;
  10. import org.springframework.scheduling.annotation.EnableAsync;
  11. import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  12.  
  13. import it.dstech.cloud.beans.TestAsync;
  14.  
  15. @Configuration
  16. @EnableAsync
  17. public class AsyncConfig implements AsyncConfigurer{
  18.    
  19.     @Bean
  20.     public TestAsync testAsyncBean() {
  21.         return new TestAsync();
  22.     }
  23.  
  24.     @Override
  25.     public Executor getAsyncExecutor() {
  26.         ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
  27.         taskExecutor.setMaxPoolSize(10);
  28.         taskExecutor.setCorePoolSize(10);
  29.         taskExecutor.setQueueCapacity(500);
  30.         taskExecutor.setThreadNamePrefix("C2CExecutor-");
  31.         taskExecutor.initialize();
  32.         return taskExecutor;
  33.     }
  34.  
  35.     @Override
  36.     public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
  37.         return new SimpleAsyncUncaughtExceptionHandler();
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement