Java Concurrency Interview

Concurrency in real systems question 132 of 180 mid

HttpClient, RestTemplate or WebClient: what concurrency questions do you ask before choosing?

All three are thread safe and meant to be shared. Creating one per request is the common mistake: it allocates a fresh connection pool, discards keep-alive, and in the worst case leaks threads, which looks like a slow memory leak and a rising thread count.

The two numbers that actually decide behaviour under load are the client's own connection pool size, which caps concurrency independently of your thread pool, and the timeouts. A missing read timeout is the single most common cause of a service that hangs with no CPU load: every worker ends up waiting forever on a dependency that will never answer.

Add a circuit breaker or a bulkhead per dependency if one slow service must not consume the capacity the others need. That bulkhead is usually a Semaphore, which is the same primitive from two topics back, applied where it belongs.

io timeouts design

Quiz yourself on Concurrency in real systems Suggest a correction