コード例 #1
0
 /**
  * Create a new instance of the {@code AsyncRestTemplate} using the given {@link
  * AsyncTaskExecutor}.
  *
  * <p>This constructor uses a {@link SimpleClientHttpRequestFactory} in combination with the given
  * {@code AsyncTaskExecutor} for asynchronous execution.
  */
 public AsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor) {
   Assert.notNull(taskExecutor, "AsyncTaskExecutor must not be null");
   SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
   requestFactory.setTaskExecutor(taskExecutor);
   this.syncTemplate = new RestTemplate(requestFactory);
   setAsyncRequestFactory(requestFactory);
 }
コード例 #2
0
  @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;
  }