You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Horia Muntean <ho...@gmail.com> on 2005/05/17 23:36:56 UTC

Is MINA's ProtocolSession thread safe?

Is Mina's ProtocolSession thread safe?

Suppose one has 2 threads that call session.write("hello"). What is the
result of such situation?

Regards,
Horia

Re: Is MINA's ProtocolSession thread safe?

Posted by Trustin Lee <tr...@gmail.com>.
Hi Horia,

2005/5/18, Horia Muntean <ho...@gmail.com>:
> Is Mina's ProtocolSession thread safe?
> 
> Suppose one has 2 threads that call session.write("hello"). What is the
> result of such situation?

First, all write requests are transferred to
ProtocolFilter.filterWrite() and IoFilter.filterWrite() of registered
filters.  The evaluation order is the exact reverse of filter chain
order.  That is, the evaluation order is C -> B -> A if your filter
chain is A->B->C.  There is no synchronization at this step.  If
you've implemented a filter, you'll have to check your filterWrite is
thread-safe.

Second, the final ByteBuffer is queued to session write queue.  This
process is fully synchronized, so you don't need to worry about it.

Thanks,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/