Reputation: 705
I'd like to know if HttpClient is thread-safe, ie can be used by 2 threads without problem. Reading the class code, it's not clear for me, as some fields are thread safe and some are not.
There has been questions not answered:
And some question seem to say it is:
Upvotes: 1
Views: 652
Reputation: 49462
The design of Jetty's HttpClient is for it to be treated the same as a Web Browser with multiple tabs open.
It is, by design, multi-threaded.
You are encouraged to only have 1 HttpClient instance started and use it repeatedly for all requests you want to make to as many servers as you want.
The Request object you create for each request is unique for that request only and cannot be reused.
There is also an active ConnectionPool that is maintained for each destination so that a minimum number of open connections is maintained, which is especially useful if you are talking to a secure SSL/TLS server (as the initial handshake to establish the connection is often the slowest part of that request/response exchange)
Upvotes: 2