public static void main(final String[] args) throws Exception {

        final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
                .setSoTimeout(Timeout.ofSeconds(5))
                .build();

        final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
                .setIOReactorConfig(ioReactorConfig)
                .evictExpiredConnections()
                .evictIdleConnections(TimeValue.ofSeconds(10))
                .build();

        client.start();

        final SimpleHttpRequest request = SimpleRequestBuilder.get()
                .setHttpHost(new HttpHost("httpbin.org"))
                .setPath("/")
                .build();

        System.out.println("Executing request " + request);
        final Future<SimpleHttpResponse> future1 = client.execute(
                SimpleRequestProducer.create(request),
                SimpleResponseConsumer.create(),
                new FutureCallback<SimpleHttpResponse>() {

                    @Override
                    public void completed(final SimpleHttpResponse response) {
                        System.out.println(request + "->" + new StatusLine(response));
                        System.out.println(response.getBody());
                    }

                    @Override
                    public void failed(final Exception ex) {
                        System.out.println(request + "->" + ex);
                    }

                    @Override
                    public void cancelled() {
                        System.out.println(request + " cancelled");
                    }

                });

        future1.get();

        Thread.sleep(TimeUnit.SECONDS.toMillis(30));

        // Previous connection should get evicted from the pool by now

        final Future<SimpleHttpResponse> future2 = client.execute(
                request,
                new FutureCallback<SimpleHttpResponse>() {

                    @Override
                    public void completed(final SimpleHttpResponse response) {
                        System.out.println(request + "->" + new StatusLine(response));
                        System.out.println(response.getBody());
                    }

                    @Override
                    public void failed(final Exception ex) {
                        System.out.println(request + "->" + ex);
                    }

                    @Override
                    public void cancelled() {
                        System.out.println(request + " cancelled");
                    }

                });

        future2.get();

        System.out.println("Shutting down");
        client.close(CloseMode.GRACEFUL);
    }
Example demonstrating how to evict expired and idle connections
from the connection pool.
httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java