[rabbitmq-discuss] Using java threadlocal for channels

Michael Klishin mklishin at gopivotal.com
Sat Mar 22 07:55:30 GMT 2014


On 21 Mar 2014, at 23:55, rails <stammailbox at gmail.com> wrote:

> Now, I understand that I would better open a channel for each thread. 
> So I use java Threadlocal for channel.
> 
> Will this slow me down?
> Is there a better way than opening a channel (and closing it for each http request)?

Clearly opening and closing a channel per request can’t be more efficient.

The question is whether the threads are long lived (e.g. you use a thread pool
such as an ExecutionService). If so, then using thread local storage for channels
should work fine. You may want to check if the channel is still open before publishing on it
and if not, open a new one.

MK

Software Engineer, Pivotal/RabbitMQ




More information about the rabbitmq-discuss mailing list