Esempio n. 1
0
  @Override
  public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor scheduler = new ThreadPoolTaskExecutor();
    scheduler.setCorePoolSize(20);
    scheduler.setMaxPoolSize(30);
    scheduler.setThreadNamePrefix("async-task-");
    scheduler.setAwaitTerminationSeconds(60);
    scheduler.setWaitForTasksToCompleteOnShutdown(true);

    scheduler.initialize();

    return scheduler;
  }
  @Bean
  @Qualifier("dnsClientHttpRequestFactory")
  public SimpleClientHttpRequestFactory dnsClientHttpRequestFactory() {
    SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();

    // Set timeouts (1 second to connect, unlimited - for response)
    clientHttpRequestFactory.setConnectTimeout(500);
    clientHttpRequestFactory.setReadTimeout(1000);

    // Setting the ThreadPoolTaskExecutor for the Async calls
    ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
    pool.setCorePoolSize(5);
    pool.setMaxPoolSize(10);
    pool.setWaitForTasksToCompleteOnShutdown(true);
    pool.initialize();

    // Setting the TaskExecutor to the ThreadPoolTaskExecutor
    clientHttpRequestFactory.setTaskExecutor(pool);

    return clientHttpRequestFactory;
  }