0

Apache's HttpClient provides mechanism to keep the socket alive.

 SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).build();
 new PoolingHttpClientConnectionManager().setDefaultSocketConfig(socketConfig)

Is there a way to enable TCP keep alive using Java 17 HttpClient?

1
  • Why? Isn’t one keepalive mechanism enough? Are you really going to keep these HTTP connections open for two hours? Commented May 6, 2024 at 20:44

1 Answer 1

-1

How about just adding a keep-alive header to your http request?

for example

HttpRequest request = HttpRequest.newBuilder().uri(URI.create("host"))
.header("Connection", "keep-alive")
.POST(json.body)).build()
Sign up to request clarification or add additional context in comments.

1 Comment

Not the same thing, although maybe the OP thinks it is, and anyway it's on by default from HTTP 1.1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.