Common configuration - Number of threads

优质
小牛编辑
127浏览
2023-12-01

Apache Http Async Client 默认启动一个调度线程,连接管理器使用多个worker线程,线程的数量和CPU核数量相同(等于 Runtime.getRuntime().availableProcessors() Runtime.getRuntime().availableProcessors()返回的数量),线程数可以修改如下:

  1. RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200))
  2. .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
  3. @Override
  4. public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
  5. return httpClientBuilder.setDefaultIOReactorConfig(
  6. IOReactorConfig.custom().setIoThreadCount(1).build());
  7. }
  8. });