问题
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager
What is the difference between these two types? Which one is more reliable in a multithreaded environment?
Thanks
回答1:
What is the difference between these two types?
PoolingHttpClientConnectionManager maintains a pool of HttpClientConnections, which provides synchronous/blocking communication.
PoolingNHttpClientConnectionManager maintains a pool of NHttpClientConnections, which provides asynchronous/non-blocking and event driven communication.
Which one is more reliable in a multithreaded environment?
Both types are annotated with @Contract which has an element to indicate the threading behavior enforced at runtime.
PoolingHttpClientConnectionManager is annotated with @Contract(threading=SAFE_CONDITIONAL)
which indicates it's thread-safe if the dependencies injected at construction time are thread-safe.
PoolingNHttpClientConnectionManager is annotated with @Contract(threading=SAFE)
, so it can be considered fully thread-safe.
来源:https://stackoverflow.com/questions/46217135/poolinghttpclientconnectionmanager-vs-poolingnhttpclientconnectionmanager