org.apache.hc.client5.http.impl.classic

## Class FutureRequestExecutionService

- java.lang.Object
- - org.apache.hc.client5.http.impl.classic.FutureRequestExecutionService

All Implemented Interfaces:
  Closeable, AutoCloseable

    @Contract(threading=SAFE_CONDITIONAL)
    public class FutureRequestExecutionService
    extends Object
    implements Closeable

This class schedules message execution execution and processing as `FutureTask`s with the provided `ExecutorService`.

### Constructor Summary

Constructors
Constructor and Description
`FutureRequestExecutionService(HttpClient httpclient, ExecutorService executorService)` Create a new FutureRequestExecutionService.

### Method Summary

Methods
`void` `close()`
`<T> FutureTask<T>` `execute(ClassicHttpRequest request, HttpContext context, HttpClientResponseHandler<T> HttpClientResponseHandler)` Schedule a request for execution.
`<T> FutureTask<T>` `execute(ClassicHttpRequest request, HttpContext context, HttpClientResponseHandler<T> HttpClientResponseHandler, FutureCallback<T> callback)` Schedule a request for execution.
`FutureRequestExecutionMetrics` `metrics()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### FutureRequestExecutionService

    public FutureRequestExecutionService(HttpClient httpclient,
                                 ExecutorService executorService)

Create a new FutureRequestExecutionService.

Parameters:
  `httpclient` - you should tune your httpclient instance to match your needs. You should align the max number of connections in the pool and the number of threads in the executor; it doesn't make sense to have more threads than connections and if you have less connections than threads, the threads will just end up blocking on getting a connection from the pool.
  `executorService` - any executorService will do here. E.g. `Executors.newFixedThreadPool(int)`

### Method Detail

#### execute

    public <T> FutureTask<T> execute(ClassicHttpRequest request,
                            HttpContext context,
                            HttpClientResponseHandler<T> HttpClientResponseHandler)

Schedule a request for execution.

Type Parameters:
  `T` -
Parameters:
  `request` - request to execute
  `HttpClientResponseHandler` - handler that will process the response.
Returns:
  HttpAsyncClientFutureTask for the scheduled request.

#### execute

    public <T> FutureTask<T> execute(ClassicHttpRequest request,
                            HttpContext context,
                            HttpClientResponseHandler<T> HttpClientResponseHandler,
                            FutureCallback<T> callback)

Schedule a request for execution.

Type Parameters:
  `T` -
Parameters:
  `request` - request to execute
  `context` - optional context; use null if not needed.
  `HttpClientResponseHandler` - handler that will process the response.
  `callback` - callback handler that will be called when the request is scheduled, started, completed, failed, or cancelled.
Returns:
  HttpAsyncClientFutureTask for the scheduled request.

#### metrics

    public FutureRequestExecutionMetrics metrics()

Returns:
  metrics gathered for this instance.
See Also:
  `FutureRequestExecutionMetrics`

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Throws:
  `IOException`