-
Sub-task
-
Resolution: Delivered
-
P4
-
21
The following methods have been added to the API:
- `void close()`: closes the client gracefully, waiting for submitted requests to complete.
- `void shutdown()`: initiates a graceful shutdown, then returns immediately without waiting for the client to terminate.
- `void shutdownNow()`: initiates an immediate shutdown, trying to interrupt active operations, and returns immediately without waiting for the client to terminate.
- `boolean awaitTermination(Duration duration)`, waits for the client to terminate, within the given duration; returns true if the client is terminated, false otherwise.
- `boolean isTerminated()`: returns true if the client is terminated.
The instances returned by `HttpClient.newHttpClient()`, and the instances built from `HttpClient.newBuilder()`, provide a best effort implementation for these methods. They allow the reclamation of resources allocated by the `HttpClient` early, without waiting for its garbage collection.
Note that an `HttpClient` instance typically manages its own pools of connections, which it may then reuse when necessary. Connection pools are typically not shared between `HttpClient` instances. Creating a new client for each operation, though possible, will usually prevent reusing such connections.
- `void close()`: closes the client gracefully, waiting for submitted requests to complete.
- `void shutdown()`: initiates a graceful shutdown, then returns immediately without waiting for the client to terminate.
- `void shutdownNow()`: initiates an immediate shutdown, trying to interrupt active operations, and returns immediately without waiting for the client to terminate.
- `boolean awaitTermination(Duration duration)`, waits for the client to terminate, within the given duration; returns true if the client is terminated, false otherwise.
- `boolean isTerminated()`: returns true if the client is terminated.
The instances returned by `HttpClient.newHttpClient()`, and the instances built from `HttpClient.newBuilder()`, provide a best effort implementation for these methods. They allow the reclamation of resources allocated by the `HttpClient` early, without waiting for its garbage collection.
Note that an `HttpClient` instance typically manages its own pools of connections, which it may then reuse when necessary. Connection pools are typically not shared between `HttpClient` instances. Creating a new client for each operation, though possible, will usually prevent reusing such connections.