Client Channel and thread safety

Shay Banon kimchy at gmail.com
Tue Oct 13 03:11:06 EDT 2009


Thanks!, had a look through the codebase last night and thats what it looked
like to me as well. 


Trustin Lee wrote:
> 
> On Tue, Oct 13, 2009 at 4:02 AM, Shay Banon <kimchy at gmail.com> wrote:
>> (sorry for posting this again, I was not subscribed to the mailing
>> list, so I am not sure it got there...)
> 
> Your message actually appeared in the mailing list.  Sorry about the late
> reply.
> 
>> Hi,
>>
>>   Quick questions, when using client bootstrap, and connecting to a
>> specific host, I get a channel back. My questions are:
>>
>> 1. Can the client bootstrap be used to connect to different host+port?
>> (I am pretty sure yes, just making sure).
> 
> Yes.  You can call connect() with different remote/local addresses as
> many times as you want.
> 
>> 2. Is the Channel that you get back from the connect operation thread
>> safe? i.e., can I do something like this:
>>
>> public void send() {
>>    ChannelBuffer cb = ... (build a new channel buffer, and fill it
>> with content)
>>    shardsChannel.write(cb)
>> }
>>
>> When channel is shared between threads, and the send method can be
>> called concurrently?
> 
> The channel is thread safe.  Therefore, you can call Channel.write()
> from different threads.
> 
> As a side note, you must make sure that the channel has completed its
> connection attempt.  Otherwise, you will get NotYetConnectedException.
>  There are many ways to get notified when the connection attempt is
> done - please refer to the examples.
> 
> HTH
> 
> — Trustin Lee, http://gleamynode.net/
> 
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Client-Channel-and-thread-safety-tp3809955p3814549.html
Sent from the Netty User Group mailing list archive at Nabble.com.



More information about the netty-users mailing list