On 06/07/2016 07:54 AM, Matt Chambers wrote:
Another way to do it would be to use ThreadLocal connections.
https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html 
<https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html>

On Jun 7, 2016, at 6:14 AM, Daniel Wu <[email protected]> wrote:

Thrift client/connection is not thread safe. Use a lock or object pool.

On 7/6/2016, 5:51 PM, "Tuan Le Dinh" <[email protected]> wrote:


You might not see too much gain in simply pooling/locking/reusing clients, as the real overhead that you are trying to avoid (I presume) is the overhead of establishing connections. Simply reusing THttpClient might not avoid this overhead.

In addition to (or perhaps instead of) reusing client instances you might want to investigate the connection pooling functionality built into Commons HTTP Components:

https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html

You could, for example, manually configure an HttpClient instance to use connection pooling and then just pass that instance to the THttpClient(String url, HttpClient client) constructor.

Reply via email to